红联Linux门户
Linux帮助

linux下的tcp扫描 C源代码

发布时间:2010-04-19 14:44:51来源:红联作者:静静飞舞
#include
#include
#include
#include
#include
#include
/*#include */

int main()
{
char ip[30];
int startport,endport,sockfd,i;
struct sockaddr_in addr;
float costtime;
clock_t start,end;
printf("Please enter the Startport\n");
scanf("%d",&startport);
printf("Please enter the Endport\n");
scanf("%d",&endport);
printf("Please enter the IP\n");
scanf("%s",ip);
if(startport<1 || endport>65535 || endport{
printf("PORT RANGE ERROR!\n");
return 0;
}
else
printf("Interesting ports %d-%d on %s \n",startport,endport,ip);
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr(ip);
start=clock();
printf(" PORT STATE\n");
for(i=startport;i<=endport;i++)
{
sockfd=socket(AF_INET,SOCK_STREAM,0);
addr.sin_port=htons(i);
if(connect(sockfd,(struct sockaddr_in *)&addr,sizeof(struct sockaddr_in))==0)
{
printf("%5d open\n",i);
close(addr);
}
}
end=clock();
costtime=(float)(end-start)/CLOCKS_PER_SEC;
printf("\nSmart Nmap finished: %s scanned in %f seconds\n",ip,costtime);
return 0;
}

本代码 本人实验过 绝对好用 有什么问题欢迎留言 交流。。。。。。。
文章评论

共有 2 条评论

  1. eddiehan 于 2010-04-24 16:52:36发表:

    收藏呢

  2. kalpoask 于 2010-04-19 14:51:06发表:

    (6)m:b