实验要求
利用socket中的sock_stream套接字实现一个TCP公开扫描程序,要求:
输入:
用户通过程序可以设定扫描的目的地址;
用户可以设定扫描端口的范围;
输出:显示被扫描目标开启了那些端口;
程序的验证: 在shell下输入命令“netstat -lnt”,对比自己程序的输出结果
实验环境
Red hat 9
代码
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
void print_usage(char* str)
{
printf("the command %s usage is:\n",str);
printf("%s Ip_Address [port] \n");
}
int scanport(int sockfd, struct sockaddr_in scanip, int port, char** arg)