|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int main(int argc , char *argv[])
{
int dst_ip;
int dst_port;
int start,last;
int sockfd;
struct sockaddr_in dst;
if(argc != 4)
{
fprintf(stderr , "usage : %s dst_ip start_port last_port\n" , argv[0]);
exit(1);
}
dst_ip = inet_addr(argv[1]);
start = atoi(argv[2]);
last = atoi(argv[3]);
sockfd = socket(AF_INET , SOCK_STREAM , 0);
if(sockfd < 0)
{
fprintf(stderr , "socket error");
exit(1);
}
for(dst_port = start ; dst_port <= last ; dst_port++)
{
memset(&dst , 0 , sizeof(dst));
dst.sin_family = AF_INET;
dst.sin_port = htons(dst_port);
dst.sin_addr.s_addr = dst_ip;
if(connect(sockfd , (struct sockaddr *)&dst , sizeof(dst)) < 0)
{
fprintf(stderr , "port %d close\n" ,dst_port);
}
else
{
fprintf(stderr , "port %d open\n" ,dst_port);
}
}
close(sockfd);
exit(0);
}
这个程序当扫描开放的端口时能显示port XX open
可当某个端口关闭时,就无法执行下去了
好比我用scan 202.23.36.56 79 81
假设202.23.36.56是个http服务,80开放
可是程序没什么反映
如果用scan 202.23.36.56 80 80
则会显示port 80 open
怎么回事啊,帮帮我啊 |
|