上機1基于WinPcap網(wǎng)絡嗅探器設計與實現(xiàn)_第1頁
上機1基于WinPcap網(wǎng)絡嗅探器設計與實現(xiàn)_第2頁
上機1基于WinPcap網(wǎng)絡嗅探器設計與實現(xiàn)_第3頁
上機1基于WinPcap網(wǎng)絡嗅探器設計與實現(xiàn)_第4頁
上機1基于WinPcap網(wǎng)絡嗅探器設計與實現(xiàn)_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、上機1:鑒于WinPcap的網(wǎng)絡嗅探器設計1、目的與要求掌握鑒于WinPcap的網(wǎng)絡編程模式。理解并能應用WinPcap設計并實現(xiàn)網(wǎng)絡數(shù)據(jù)包的捕捉與分析。2、設施與上機環(huán)境連網(wǎng)PC機(起碼一臺)。計算機硬件要求:IntelPentium5辦理器、256MB以上內存,Ethernet網(wǎng)卡,網(wǎng)線若干。計算機軟件要求:MSWindows9x/2000/XP操作系統(tǒng),TCP/IP協(xié)議,WinPcap430,Visualc+6.0/.net系統(tǒng)。3、上機內容與步驟:在程序設計以前,請參照供給的軟件安裝WinPcap。以后,依據(jù)以下步驟操作:步驟1:在VC+6.0下創(chuàng)立一個DOS命令行程序,工程名:自己的

2、學號-PacketDump步驟2:翻開main()函數(shù),在主程序中增添以下頭文件和常量定義:#include#defineLINE_LEN16pcap_if_t*alldevs,*d;pcap_t*fp;u_intinum,i=0;charerrbufPCAP_ERRBUF_SIZE;intres;structpcap_pkthdr*header;constu_char*pkt_data;printf(pktdump_ex:printsthepacketsofthenetworkusingWinPcap.n);printf(Usage:pktdump_ex-ssourcennExamples:

3、npktdump_ex-snpktdump_ex-sDeviceNPF_C8736017-F3C3-4373-94AC-9A34B7DAD998nn);if(argcnext)printf(%d.%sn,+i,d-name);if(d-description)printf(%s)n,d-description);elseprintf(Nodescriptionavailable)n);if(i=0)printf(nNointerfacesfound!MakesureWinPcapisinstalled.n);return-1;printf(Entertheinterfacenumber(1-%

4、d):,i);scanf(%d,&inum);if(inumi)printf(nInterfacenumberoutofrange.n);/*Freethedevicelist*/pcap_freealldevs(alldevs);return-1;/*Jumptotheselectedadapter*/for(d=alldevs,i=0;inext,i+);/*Opentheadapter*/if(fp=pcap_open_live(d-name,65536,/nameofthedevice/portionofthepackettocapture./65536grantsthatthewho

5、lepacketwillbecapturedonalltheMACs.1,/promiscuousmode(nonzeromeanspromiscuous)1000,errbuf)=NULL)/readtimeout/errorbufferfprintf(stderr,nErroropeningadaptern);return-1;else/*Donotcheckfortheswitchtype(-s)*/if(fp=pcap_open_live(argv2,/nameofthedevice65536,/portionofthepackettocapture./65536grantsthatt

6、hewholepacketwillbecapturedonalltheMACs.1,/promiscuousmode(nonzeromeanspromiscuous)1000,/readtimeouterrbuf/errorbuffer)=NULL)fprintf(stderr,nErroropeningadaptern);return-1;/*Readthepackets*/while(res=pcap_next_ex(fp,&header,&pkt_data)=0)if(res=0)/*Timeoutelapsed*/continue;/*printpkttimestampandpktle

7、n*/printf(%ld:%ld(%ld)n,header-ts.tv_sec,header-ts.tv_usec,header-len);/*Printthepacket*/for(i=1;(icaplen+1);i+)printf(%.2x,pkt_datai-1);if(i%LINE_LEN)=0)printf(n);printf(nn);if(res=-1)printf(Errorreadingthepackets:%sn,pcap_geterr(fp);return-1;pcap_close(fp);return0;步驟3:為編譯器指定包括文件和庫文件搜尋目錄。假設WinPcap開發(fā)包WpdPack_4_0_2.zip被解壓縮到C盤,以下列圖:為編譯器指定包括文件和庫文件搜尋目錄的方法以下:在VC+6.0下,翻開Tools菜單,選擇Options,而后選擇Directories選項卡,指定WinPcap包括文件和庫文件目錄,以下列圖所示。步驟4:指定鏈接的庫文件。方法:翻開Project菜單,選擇Settings,選擇Link選項卡,而后把wpcap.lib、ws2_32.lib

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論