91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 101KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-08-03
  • 語言: 其他
  • 標簽:

資源簡介

計算機網絡高級軟件編程技術第5章 IP包流量分析程序源代碼

資源截圖

代碼片段和文件信息

#include?“IPMonitor.h“

#define?BURRER_SIZE?65535

void?main(int?argcchar?*?argv[])
{
//?判斷輸入的命令行格式是否正確
if?(argc?!=?2)
{
cout?< < return;
}

WSADATA?wsData;

//?初始化Winsock?DLL
if?(WSAStartup(MAKEWORD(22)&wsData)?!=?0)
{
cout?< return;
}

//?創建Raw?Socket
SOCKET?sock;
if?(?(sock?=?WSASocket(AF_INET?SOCK_RAW?IPPROTO_IP?NULL?0?WSA_FLAG_OVERLAPPED))?
==?INVALID_SOCKET?)
{
cout?< return;
}

//?設置IP頭操作選項,表示用戶可以親自對IP頭進行處理
BOOL?bFlag?=?TRUE;
if?(setsockopt(sock?IPPROTO_IP?IP_HDRINCL?(char?*)&bFlag?sizeof(bFlag))?==?SOCKET_ERROR)
{
cout?< return;
}

//?獲取本地主機名
char?pHostName[128];
if?(gethostname(pHostName?100)?==?SOCKET_ERROR)
{
cout?< return;
}

//?通過本地主機名獲取本地IP地址
hostent?*?pHostIP;
if((pHostIP?=?gethostbyname(pHostName))?==?NULL)
{
cout<<“Gethostbyname?failed!“< return;
}

//?填充sockaddr_in結構
sockaddr_in?addr_in;
addr_in.sin_addr?=?*(in_addr?*)pHostIP->h_addr_list[0]; ?//?設定IP地址
addr_in.sin_family?=?AF_INET; //?設定地址類型
addr_in.sin_port?=?htons(8000); //?設定端口

//?把原始套接字綁定到本機地址上
if(bind(sock(PSOCKADDR)&addr_insizeof(addr_in))?==?SOCKET_ERROR)
{
cout?< return;
}

//?把網卡設置為混雜模式,以便接收所有的IP包
#define??IO_RCVALL?_WSAIOW(IOC_VENDOR1)
unsigned?long?pBufferLen[10];
unsigned?long?dwBufferInLen?=?1;
unsigned?long?dwBytesReturned?=?0;
if?((WSAIoctl(sock?IO_RCVALL?&dwBufferInLen?sizeof(dwBufferInLen)?&pBufferLen
sizeof(pBufferLen)?&dwBytesReturned?NULL?NULL))?==?SOCKET_ERROR)
{
cout<<“Ioctlsocket?failed!“< return;
}

//?把socket設置為非阻塞模式
unsigned?long?dwTemp?=?1;
????ioctlsocket(sock?FIONBIO?&dwTemp);

//?設置接收緩沖區
char?pBuffer[BURRER_SIZE];

//?定義存放IP數據包的鏈表
CNodeList?IpList;

double?dwDuration?=?atof(argv[1]); //?輸入參數為捕獲時間
time_t?beg;
time_t?end;
time(&beg); //?獲得當前系統時間

//?輸出本地IP地址
cout?< cout?< ?< cout?<
while?(1)
{
time(&end); //?獲得當前系統時間
//如果捕獲時間到,就結束捕獲
if?(end-beg?>=?dwDuration)
{
break;
}

//?捕獲經過網卡的IP數據包
int?nPacketSize?=?recv(sockpBufferBURRER_SIZE0);
if?(nPacketSize?>?0)
{
IPHEADER?*?pIpHdr;
//?通過指針把緩沖區中的內容強制轉換為IPHEADER數據結構
pIpHdr?=?(IPHEADER?*)pBuffer;
//?判斷IP包的源IP地址或目的IP地址是否為本地主機的IP地址
if?(pIpHdr->SourceAddress?==?addr_in.sin_addr.S_un.S_addr?
||?pIpHdr->DestAddress?==?addr_in.sin_addr.S_un.S_addr)?
{
//?如果源IP地址或目的IP地址是本機IP,則將該IP數據包加入鏈表
IpList.addNode(pIpHdr->SourceAddress?pIpHdr->DestAddress?pIpHdr->Protocal);
}
}
}

//?輸出統計結果
cout?<

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????3370??2007-06-15?08:44??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.cpp

?????文件???????4634??2007-06-15?09:15??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.dsp

?????文件????????541??2006-10-30?08:00??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.dsw

?????文件????????797??2007-06-15?08:54??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.h

?????文件?????140288??2007-06-27?16:23??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.ncb

?????文件??????54784??2007-06-27?16:23??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.opt

?????文件???????1457??2007-06-27?16:22??第5章?IP包流量分析程序\IPMonitor\Code\IPMonitor.plg

?????文件???????1373??2007-06-15?09:06??第5章?IP包流量分析程序\IPMonitor\Code\IPNode.cpp

?????文件???????1140??2007-06-15?09:14??第5章?IP包流量分析程序\IPMonitor\Code\IPNode.h

?????文件???????2022??2007-06-15?09:14??第5章?IP包流量分析程序\IPMonitor\Code\NodeList.cpp

?????文件????????902??2007-06-15?09:10??第5章?IP包流量分析程序\IPMonitor\Code\NodeList.h

?????文件?????254090??2007-06-27?16:22??第5章?IP包流量分析程序\IPMonitor\Exe\IPMonitor.exe

?????文件??????45568??2007-06-30?12:20??第5章?IP包流量分析程序\IPMonitor\使用說明.doc

?????文件????????119??2010-05-20?15:07??第5章?IP包流量分析程序\我的空間.url

?????文件????????125??2010-05-20?15:08??第5章?IP包流量分析程序\說明.url

?????目錄??????????0??2010-05-20?15:07??第5章?IP包流量分析程序\IPMonitor\Code

?????目錄??????????0??2010-05-20?15:07??第5章?IP包流量分析程序\IPMonitor\Exe

?????目錄??????????0??2010-05-20?15:07??第5章?IP包流量分析程序\IPMonitor

?????目錄??????????0??2010-05-20?15:08??第5章?IP包流量分析程序

-----------?---------??----------?-----??----

???????????????511210????????????????????19


評論

共有 條評論