源码地带 > 电路图 > 电子资料下载 > 网络 >当今 > 查看压缩包源码

当今

源代码在线查看: a simple port scan.txt

软件大小: 181 K
上传用户: a6810121
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				发信人: lgwu (乱世糊涂虫), 信区: Security 

				标  题: a simple port scan 

				发信站: 武汉白云黄鹤站 (Fri Jan 29 21:00:02 1999) , 站内信件 

				  

				static char sccsid[] = "@(#)pscan.c     1.0     (KRAD) 08/25/94"; 

				                    #include  

				                    #include  

				                    #include  

				                    #include  

				                    #include  

				  

				                    #define MAX_PORT 1024 /* scan up to this port */ 

				                    int s; 

				                    struct sockaddr_in addr; 

				                    char rmt_host[100]; 

				  

				                    int skan(port) 

				                    int port; 

				                    { 

				                     int r; 

				                        s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); 

				                        if (s < 0) { 

				                           /* fprintf("ERROR: socket() failed\n"); */ 

				                           /* Changed to printf for my Linux 1.1.18 box */ 

				                           printf("ERROR: socket() failed\n"); 

				                           exit(0); 

				                      } 

				  

				                        addr.sin_family = PF_INET; 

				                        addr.sin_port = htons(port); 

				                        addr.sin_addr.s_addr = inet_addr(rmt_host); 

				  

				                        r = connect(s,(struct sockaddr *) &addr, sizeof(addr)); 

				  

				                        close(s); 

				                        if (r==-1) { 

				                           return (1 == 0); 

				                        } 

				  

				                        return (1 == 1); 

				                    } 

				  

				                    main(argc,argv) 

				                    int argc; 

				                    char *argv[]; 

				                    { 

				                     int a,b,c,d,e,f; 

				                     struct hostent *foo; 

				                    struct servent *bar; 

				  

				                       if (argc < 2) { 

				                          fprintf(stderr,"usage: %s  [highest port]\n",arg 

				v[0]); 

				                          exit(0); 

				                       } 

				  

				                       if (sscanf(argv[1],"%d.%d.%d.%d",&a,&b,&c,&d) != 4) { 

				                          foo = gethostbyname(argv[1]); 

				                          if (foo == NULL) { 

				                             fprintf(stderr,"error: cannot resolve host %s\n",ar 

				gv[1]); 

				                             exit(0); 

				                          } 

				                          sprintf(rmt_host,"%d.%d.%d.%d",(unsigned char )foo->h_ 

				addr_list[0][0], 

				                                  (unsigned char ) foo->h_addr_list[0][1], 

				                                  (unsigned char ) foo->h_addr_list[0][2], 

				                                  (unsigned char ) foo->h_addr_list[0][3]); 

				                       } else { 

				                          strncpy(rmt_host,argv[1],99); 

				                       } 

				  

				  

				                       if (argc > 2) { 

				                          f = atoi(argv[2]); 

				                       } else 

				                          f = MAX_PORT; 

				  

				                       fprintf(stdout,"Scanning host %s - TCP ports 1 through %d 

				\n",rmt_host,f); 

				  

				                       for (e =1;e				                        char serv[100]; 

				                          if (skan(e)) { 

				                             bar = getservbyport(htons(e),"tcp"); 

				                             printf("%d (%s) is running.\n",e,(bar == NULL) ? "U 

				NKNOWN" : 

				                                    bar->s_name); 

				

				                          } 

				                       } 

				                    } 

				 /* This simple port scan program can be found in /var/log/messages */ 

				But if u use nmap( half connect,NULL connect,a normal TCPwarp couldn't 

				find it out. As a patch,you can use tcplog.I  posted it before. 

				  

				  

				-- 

							

相关资源