int main(int argc, const char * argv[]) { // insert code here... if (argc < 4) { printf("参数错误,正确命令:扫描的IP地址 开始端口 结束端口 [线程数]\n"); return 0; } printf("端口扫描开始\n"); //int fd[65535]; char *ip = argv[1]; int s_port = atoi(argv[2]); int e_port = atoi(argv[3]); int open[65535]; int count = 0; if(argc == 5) { //使用多线程方式 int ts = atoi(argv[4]); res = (int **)malloc(sizeof(int*)*ts); mulite_thread_run(ip, s_port, e_port,ts); }else{ //使用单线程 for (int i = s_port; i <= e_port; i++) { printf("开始扫描%d号端口\n",i); int r = -1; if ((r=conn_nonb(ip, i, 100)) == 0) { open[count] = i; count++; } } } return 0; }
int main(int argc, const char * argv[]) { // insert code here... if (argc < 4) { printf("arg input error,plz use: target_ip start_port end_port [theads num]\n"); return 0; } printf("----start----\n"); //int fd[65535]; char *ip = argv[1]; int s_port = atoi(argv[2]); int e_port = atoi(argv[3]); int open[65535]; int count = 0; if(argc == 5) { //multiple threads int ts = atoi(argv[4]); res = (int **)malloc(sizeof(int*) * ts); mulite_thread_run(ip, s_port, e_port,ts); }else{ //single thread for (int i = s_port; i <= e_port; i++) { //printf("scan %d port\n",i); int r = -1; if ((r = conn_nonb(ip, i, TIMEOUT)) == 0) { open[count] = i; count++; } } } return 0; }