資源簡介
這是一份完整的監控IP包流量的計算機網絡課程設計,包含VC工程文件和課程設計報告,里面還有關于cmd最常用的命令簡介和一個winpacp安裝文件。

代碼片段和文件信息
#include
#include
#include
#include
#include
#include
#include“pcap.h“
#include“IPNodeList.h“
#pragma?comment(lib“Wpcap.lib“)??
#pragma?comment(lib“Ws2_32.lib“)
struct?ip_header
{
unsigned?char??ver_ihl;//版本號(4)+頭部長度(4)
unsigned?char??tos;
unsigned?short?tlen;???//總長度
unsigned?short?identification;//標識
unsigned?short?flags_fo;
unsigned?char??ttl;
unsigned?char??proto;??//協議
unsigned?short?crc;
DWORD??????????saddr;??//源地址
DWORD??????????daddr;??//目的地址
unsigned?int???op_pad;?//選項+填充
};
void?main(int?argcchar*?argv[])
{
if(argc!=3)
{
cout<<“usage:IP?Statistic?time?logfile“< cout<<“press?any?key?to?continue...“< _getch();
return;
}
double????min=atof(argv[1]);//argv:時間,字符串轉換另:atof()函數將字符串轉換成浮點型數;
pcap_if_t?*alldevs; ????????//pcap_if_t是pcap_if的宏定義,是網絡設備結構的列表,列表的每一項包含關于適配器的復雜的信息
pcap_if_t?*d*head=NULL;
pcap_t????*fp;
char??????errbuf[PCAP_ERRBUF_SIZE];
unsigned?int????netmask;
char??????packet_filter[]=“ip“;//過濾規則
struct????bpf_program??fcode;
struct????pcap_pkthdr??*header;
const??unsigned?char???*pkt_data;
//獲取網路設備列表
if(pcap_findalldevs(&alldevserrbuf)==-1)
{
cout<<“Error?in?pcap_findalldevs:“< return;
}
int?i;
int?j=0;
for(d=alldevs;d;d=d->next)//列出網卡列表
{
cout<<++j<<“:?“<name;
if(d->description)
cout<<“??“<description< }
cout<<“\nEnter?the?interface?number?(1-“< int?k;
cin>>k;
if(k<1||k>j)
{
cout<<“out?of?range“< return;
}
for(d=alldevsi=1;inexti++);
head=d;
//以混雜模式打開網卡
if((fp=pcap_open_live(head->name100011000errbuf))==NULL)//監聽的設備接口名,最大數目的網絡數據包,是否混雜,超時時間,存儲出錯信息
{
cout<<“\nUnable?to?open?the?adapter.“< pcap_freealldevs(alldevs);
return;
}
//獲得子網掩碼
if(head->addresses?!=NULL)
netmask=((struct?sockaddr_in*)(head->addresses->netmask))->sin_addr.S_un.S_addr;//將二進制IP轉化為點進十進制
else?
netmask=0xffffff;
//編譯過濾器
if(pcap_compile(fp&fcodepacket_filter1netmask)<0)//packet_filter:規則表達式格式的過濾規則,netmask:監聽接口的網絡掩碼
{
cout<<“\nUnable?to?compile?the?packet?filter.?Check?the?syntax.?\n?“;
pcap_freealldevs(alldevs);
return;
}
//設置過濾器
if(pcap_setfilter(fp&fcode)<0)//pcap的會話句柄;經過編譯后的過濾規則,返回-1表示操作失敗,其他值表成功
{
cout<<“\nError?setting?the?filter.\n“;
pcap_freealldevs(alldevs);
????return;
}
//顯示提示信息及每項含義
cout<<“\nlistening?on“<description<<“...“< ofstream?fout(argv[2]ios::app);????//
fout<<“\tIP?Statistic:(“< time_t?tmp=time(NULL);??????????????//
fout< cout<<“IP?Statistic:(“< fout<<“???Sour?IP?????“<<“\tpacket?numbers“<
//釋放設備列表
pcap_freealldevs(alldevs);
NodeList?link;//定義結點鏈表link
int????res;
time_t?beg;???//time_t是long型的變量,當前時間
time_t?end;???//結束時間
time(&beg);???//
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????0??2010-06-25?10:58??IPMONITOR\Debug\a.txt
?????文件???????3886??2010-06-24?19:13??IPMONITOR\Debug\BuildLog.htm
?????文件????2032640??2010-06-23?18:06??IPMONITOR\Debug\IPMONITOR.bsc
?????文件?????254011??2010-06-26?20:50??IPMONITOR\Debug\IPMONITOR.exe
?????文件?????327256??2010-06-26?20:50??IPMONITOR\Debug\IPMONITOR.ilk
?????文件??????30682??2010-06-26?20:50??IPMONITOR\Debug\ipmonitor.obj
?????文件????4867136??2010-06-26?20:37??IPMONITOR\Debug\IPMONITOR.pch
?????文件?????648192??2010-06-26?20:50??IPMONITOR\Debug\IPMONITOR.pdb
?????文件????1003136??2010-06-26?20:50??IPMONITOR\Debug\ipmonitor.sbr
?????文件???????3584??2010-06-24?19:22??IPMONITOR\Debug\IPMONITOR.suo
?????文件?????279552??2010-06-26?20:50??IPMONITOR\Debug\vc60.idb
?????文件?????102400??2010-06-26?20:50??IPMONITOR\Debug\vc60.pdb
?????文件??????76800??2010-06-24?19:13??IPMONITOR\Debug\vc90.idb
?????文件?????135168??2010-06-24?19:13??IPMONITOR\Debug\vc90.pdb
?????文件???????1555??2010-06-13?19:58??IPMONITOR\Debug\命令提示符.lnk
?????文件???????4049??2010-06-26?20:50??IPMONITOR\ipmonitor.cpp
?????文件???????4462??2010-06-24?16:44??IPMONITOR\IPMONITOR.dsp
?????文件????????541??2010-06-22?21:11??IPMONITOR\IPMONITOR.dsw
?????文件??????74752??2010-06-26?20:50??IPMONITOR\IPMONITOR.ncb
?????文件??????70656??2010-06-26?20:50??IPMONITOR\IPMONITOR.opt
?????文件???????1299??2010-06-26?20:50??IPMONITOR\IPMONITOR.plg
?????文件????????883??2010-06-24?19:08??IPMONITOR\IPMONITOR.sln
????..A..H.?????10752??2010-06-24?19:14??IPMONITOR\IPMONITOR.suo
?????文件???????5368??2010-06-24?19:08??IPMONITOR\IPMONITOR.vcproj
?????文件???????1427??2010-06-24?19:14??IPMONITOR\IPMONITOR.vcproj.PC2010060420VAO.Administrator.user
?????文件???????2011??2010-06-26?20:37??IPMONITOR\IPNodeList.h
?????文件??????15467??2010-06-24?16:25??IPMONITOR\PCAP.H
?????文件??????84480??2010-06-26?20:46??課程設計報告:監控IP包流量.doc
?????文件????????221??2010-06-26?20:49??CMD命令最常用命令簡介.txt
?????文件?????550560??2008-07-08?11:02??WinPcap_4_0_2.exe
............此處省略6個文件信息
評論
共有 條評論