资源简介
用C语言编写扫描局域网内主机的程序。要求可以显示局域网内的主机名列表,IP地址列表,并可以显示哪些主机开放了哪些端口
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#pragma comment (lib“ws2_32.lib“)
typedef struct
{
char ip[20];
int port;
bool flag;
}infor;
int Lastip;
int nowport;
int startPort;
int endPort;
int threadnum = 0; //线程计数
DWORD WINAPI pScan(LPVOID lp);
void scanip (int ip1 int ip2 int ip3 int ip4);//端口扫描函数
ofstream SaveFile (“result.txt“); //设置输出文件
int check(char startip[]){
int count =0;
for(int i = 0;startip[i]!=‘\0‘;i++)
{
if (startip[i] ==‘.‘)
{
count++;
if(startip[i+1] ==‘.‘)
{
cout<<“输入的ip地址有误,重新输入\n“;
return 1;
}
}
else if(!(startip[i]<=‘9‘&&startip[i]>=‘0‘))
{
cout<<“输入的ip地址有误,重新输入\n“;
return 1;
}
}
if(count!=3)
{
cout<<“输入的ip地址有误,重新输入\n“;
return 1;
}
return 0;
}
int main ()
{
bool inFlag =true;
char startip[20]=“172.19.160.60“; //起始IP
char endip[20];//=“172.19.160.80“; //中止IP
//将ip转化为4段整数
int ip1 ip1end ip2 ip2end ip3 ip3end ip4 ip4end;
while(inFlag){
cout << “请输入起始IP:“ << “172.19.160.60“<
//cin >> startip;
if(check(startip))continue;
cout << “请输入终止IP:“; //<<“172.19.160.80“<< endl;
cin >> endip;
if(check(endip))continue;
cout << “请输入起始端口:“ <<“0“<< endl;
//cin >> startPort;
startPort=0;
cout << “请输入终止端口:“ <<“255“<< endl;
//cin >> endPort;
endPort=255;
//将startip转化为4段整数
ip1 = atoi (strtok (startip “.“));
ip2 = atoi (strtok (NULL “.“));
ip3 = atoi (strtok (NULL “.“));
ip4 = atoi (strtok (NULL “.“));
//将endip转化为4段整数
ip1end = atoi (strtok (endip “.“));
ip2end = atoi (strtok (NULL “.“));
ip3end = atoi (strtok (NULL “.“));
ip4end = atoi (strtok (NULL “.“));
//检测ip合法性
if((ip1<=0 ||ip1>=255)||(ip2<=0 ||ip2>=255)||(ip3<=0 ||ip3>=255)||(ip4<=0 ||ip4>=255)||
(ip1end<=0 ||ip1end>=255)||(ip2end<=0 ||ip2end>=255)||(ip3end<=0 ||ip3end>=255)||(ip4end<=0 ||ip4end>=255))
{
cout<<“输入的ip地址有误,重新输入\n“;
}
else
inFlag=false;
}
//从startip到endip开始扫描
while (ip1 < ip1end)
{
while (ip2 <= 255)
{
while (ip3 <= 255)
{
while (ip4 <= 255)
{
scanip (ip1 ip2 ip3 ip4);
ip4++;
}
ip3++;
ip4 = 0;
}
ip2++;
ip3 = 0;
}
ip1++;
ip2 = 0;
}
while (ip2 < ip2end)
{
while (ip3 <= 255)
{
while (i
- 上一篇:画直角坐标系
- 下一篇:数据结构课程设计《活期储蓄帐目管理》c语言实现
相关资源
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- 基于mfc的多线程文件传输
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 利用C++哈希表的方法实现电话号码查
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 移木块游戏,可以自编自玩,vc6.0编写
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- C++纯文字DOS超小RPG游戏
- 个人日常财务管理系统(C语言)
- MFC数字钟(基于VC6.0)
- c语言电子商务系统
评论
共有 条评论