您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 发现网络中的活动主机
  所属分类: Web开发
  开发工具:
  文件大小: 6kb
  下载次数: 0
  上传时间: 2008-12-21
  提 供 者: yunbi*****
 详细说明: #pragma pack(4) //#include "stdafx.h" #pragma comment (lib,"Ws2_32.lib") #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include #include typedef struct iphdr { unsigned int headlen:4; unsigned int version:4; unsigned char tos; unsigned short totallen; unsigned short id; unsigned short falg; unsigned char ttl; unsigned char prot; unsigned short checksum; unsigned int sourceIP; unsigned int destIP; }IpHeader; typedef struct icmphdr { BYTE type; BYTE code; USHORT checksum; USHORT id; USHORT seg; }IcmpHeader; #define ICMP_RCHO 8 #define ICMP_RCHO_REPLY 0 #define ICMP_MIN 8 #define STATUS_FAILED 0xFFFF #define DEF_PACKET_SIZE 32 #define MAX_PACKET 1024 #define MAX_PING_PACKET_SIZE (MAX_PACKET+sizeof(IpHeader)) void fill_icmp_data(char *,int); USHORT checksum(USHORT *,int); void decode_resp(char *,int,struct sockaddr_in *); DWORD WINAPI FindIP(LPVOID pIPAddrTemp); WSADATA wsaData; SOCKET sockRaw; struct sockaddr_in dest,from,end; int fromlen =sizeof(from); char *recvbuf=new char[MAX_PING_PACKET_SIZE]; unsigned int addr=0; long ThreadNumCounter=0,ThreadNumLimit=20; long *aa=&ThreadNumCounter; void main(int argc,char *argv[]) { /*if(argc!=3) { cout<<"输入格式错误: start_ip end_ip"<ThreadNumLimit) { Sleep(5000); continue; } DWORD ThreadID; sockaddr_in *pIPAddrTemp=new (sockaddr_in); if(!pIPAddrTemp) { cout<<"memory alloc failed"<type=ICMP_RCHO; icmp_hdr->id=(USHORT)GetCurrentThreadId(); datapart=icmp_data+sizeof(IcmpHeader); memset(datapart,'A',datasize-sizeof(IcmpHeader)); } void decode_resp(char *buf,int bytes,struct sockaddr_in *from) { IpHeader *iphdr; IcmpHeader *icmphdr; unsigned short iphdrlen; iphdr=(IpHeader*) buf; iphdrlen=iphdr->headlen*4; icmphdr=(IcmpHeader *)(buf+iphdrlen); if(bytestype!=ICMP_RCHO_REPLY)return; if(icmphdr->id!=(USHORT)GetCurrentThreadId())return; cout<<"活动主机: "<sin_addr)<1) { cksum+=*buffer++; size-=sizeof(USHORT); } if(size) { cksum+=*(UCHAR*)buffer; } cksum=(cksum>>16)+(cksum& 0xffff); cksum+=(cksum>>16); return (USHORT)(~cksum); } DWORD WINAPI FindIP(LPVOID pIPAddrTemp) { InterlockedIncrement(aa); char icmp_data[MAX_PACKET]; memset(icmp_data,0,MAX_PACKET); int datasize=DEF_PACKET_SIZE; datasize+=sizeof(IcmpHeader); fill_icmp_data(icmp_data,datasize); ((IcmpHeader*)icmp_data)->checksum=0; ((IcmpHeader*)icmp_data)->seg=0; ((IcmpHeader*)icmp_data)->checksum=checksum((USHORT*)icmp_data,datasize); int bwrote=sendto(sockRaw,icmp_data,datasize,0,(struct sockaddr *)pIPAddrTemp,sizeof(dest)); int n=0; if(bwrote==SOCKET_ERROR) { if(WSAGetLastError()==WSAETIMEDOUT) { cout<<"timed out"<
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: C程序
 输入关键字,在本站1000多万海量源码库中尽情搜索: