資源簡介
網絡應用課程設計的發現網絡中的活動主機C++版 其中有運行文件+源碼+實驗報告+答辯PPT

代碼片段和文件信息
#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?*intstruct?sockaddr_in?*);
DWORD?WINAPI?FindIP(LPVOID?pIPAddrTemp);
WSADATA?wsaData;
SOCKET?sockRaw;
struct?sockaddr_in?destfromend;
int?fromlen?=sizeof(from);
char?*recvbuf=new?char[MAX_PING_PACKET_SIZE];
unsigned?int?addr=0;
long?ThreadNumCounter=0ThreadNumLimit=20;
long?*aa=&ThreadNumCounter;
void?main(int?argcchar?*argv[])
{
/*if(argc!=3)
{
cout<<“輸入格式錯誤:?start_ip?end_ip“< return;
}*/
if(WSAStartup(MAKEWORD(21)&wsaData)!=0)
{
cout<<“WASStartup?failed“< ExitProcess(STATUS_FAILED);
}
sockRaw=WSASocket(AF_INETSOCK_RAWIPPROTO_ICMPNULL0WSA_FLAG_OVERLAPPED);
if(sockRaw==INVALID_SOCKET)
{
cout<<“WASSocketet()?falied“< ExitProcess(STATUS_FAILED);
}
int?timeout=1000;
int?bread=setsockopt(sockRawSOL_SOCKETSO_RCVTIMEO(char?*)&timeoutsizeof(timeout));
if(bread==SOCKET_ERROR)
{
cout<<“FAILED?TO?SEY?RECV?TIMEOUT“< ExitProcess(STATUS_FAILED);
}
?timeout=1000;
?bread=setsockopt(sockRawSOL_SOCKETSO_SNDTIMEO(char?*)&timeoutsizeof(timeout));
?if(bread==SOCKET_ERROR)
{
cout<<“FAILED?TO?SEY?RECV?TIMEOUT“< ExitProcess(STATUS_FAILED);
}
memset(&dest0sizeof(dest));
unsigned?long?startIPendIP;
dest.sin_family=AF_INET;
dest.sin_addr.s_addr=inet_addr(argv[1]);
startIP=inet_addr(argv[1]);
end.sin_family=AF_INET;
end.sin_addr.s_addr=inet_addr(argv[2]);
endIP=inet_addr(argv[2]);
HANDLE?hThread;
while(htonl(startIP)<=htonl(endIP))
{
if(ThreadNumCounter>ThreadNumLimit)
{
Sleep(5000);
continue;
}
DWORD?ThreadID;
sockaddr_in?*pIPAddrTemp=new?(sockaddr_in);
if(!pIPAddrTemp)
{
cout<<“memory?alloc?failed“< return?;
}
*pIPAddrTemp=dest;
clock_t?start;
start=clock();
hThread=CreateThread(NULLNULLFindIP(LPVOID)pIPAddrTempNULL&ThreadID);
long?i=60000000L;
while(i--);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????208947??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\sendhost.exe
?????文件?????246132??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\sendhost.ilk
?????文件??????21427??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\sendhost.obj
?????文件????2011816??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\sendhost.pch
?????文件?????418816??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\sendhost.pdb
?????文件??????99328??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\vc60.idb
?????文件??????69632??2012-05-31?10:19??發現網絡中的活動主機\sendhost\Debug\vc60.pdb
?????文件???????5826??2012-05-31?10:20??發現網絡中的活動主機\sendhost\sendhost.cpp
?????文件???????4308??2012-05-31?10:20??發現網絡中的活動主機\sendhost\sendhost.dsp
?????文件????????524??2012-05-31?10:19??發現網絡中的活動主機\sendhost\sendhost.dsw
?????文件??????33792??2012-05-31?10:20??發現網絡中的活動主機\sendhost\sendhost.ncb
?????文件??????48640??2012-05-31?10:20??發現網絡中的活動主機\sendhost\sendhost.opt
?????文件????????898??2012-05-31?10:19??發現網絡中的活動主機\sendhost\sendhost.plg
?????文件???????8957??2012-05-31?10:30??發現網絡中的活動主機\wangluo.png
?????文件?????181248??2012-05-31?10:16??發現網絡中的活動主機\實驗.ppt
?????文件?????144506??2012-05-31?13:45??發現網絡中的活動主機\實驗報告.doc
?????目錄??????????0??2012-05-31?13:47??發現網絡中的活動主機\sendhost\Debug
?????目錄??????????0??2012-05-31?13:47??發現網絡中的活動主機\sendhost
?????目錄??????????0??2012-05-31?13:47??發現網絡中的活動主機\VC6.0運行出來的文件
?????目錄??????????0??2012-05-31?13:48??發現網絡中的活動主機
-----------?---------??----------?-----??----
??????????????3504797????????????????????20
- 上一篇:C語言實戰-學生成績管理系統
- 下一篇:計算N階乘n>20)用鏈表形式
評論
共有 條評論