已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Winpcap安装方法Winpcap功能强大,效率高,使用方便,但是,使用前的准备工作要费一番功夫,步骤如下: 步骤1:安装驱动程序。下载WinPcap Driver和DLL并安装,安装后重启机器。 步骤2:下载wpdpack(Developers pack)。解压后会看到其中包含了docs、Include、lib、Examples等文件夹。 步骤3:在VC中设定Include目录及Library目录。具体做法:打开VC后,Tools-Option-Directories,在include files中添加wpdpackInclude目录(步骤2中得到的);在Library files中添加wpdpackLib目录。 步骤4:Project-settings-Link,在Object/library modules中加上wpcap.lib。然后测试下:#include pcap.hvoid main() pcap_if_t *alldevs; pcap_if_t *d; int i=0; char errbufPCAP_ERRBUF_SIZE; /* 这个API用来获得网卡 的列表 */ if (pcap_findalldevs(&alldevs, errbuf) = -1) fprintf(stderr,Error in pcap_findalldevs: %sn, errbuf); exit(1); /* 显示列表的响应字段的内容 */ for(d=alldevs;d;d=d-next) printf(%d. %s, +i, d-name); if (d-description) printf(nttDescription: (%s)n, d-description); else printf( (No description available)n); if(i=0) printf(nNo interfaces found! Make sure WinPcap is installed.n); return; /* We dont need any more the device list. Free it */ pcap_freealldevs(alldevs);以上是在vc6里面的测试换成.net或者vs2005 ,可以更加简/* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)* All rights reserved.* Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:* 1. Redistributions of source code must retain the above copyright* notice, this list of conditions and the following disclaimer.* 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in the* documentation and/or other materials provided with the distribution.* 3. Neither the name of the Politecnico di Torino, CACE Technologies * nor the names of its contributors may be used to endorse or promote * products derived from this software without specific prior written * permission.* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS* AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#include pcap.h#ifndef WIN32#include #include #else#include #endif/ Function prototypesvoid ifprint(pcap_if_t *d);char *iptos(u_long in);char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);int main()pcap_if_t *alldevs;pcap_if_t *d;char errbufPCAP_ERRBUF_SIZE+1;char sourcePCAP_ERRBUF_SIZE+1;printf(Enter the device you want to list:n rpcap:/ = lists interfaces in the local machinen rpcap:/hostname:port = lists interfaces in a remote machinen (rpcapd daemon must be up and runningn and it must accept null authentication)n file:/foldername = lists all pcap files in the give foldernn Enter your choice: );fgets(source, PCAP_ERRBUF_SIZE, stdin);sourcePCAP_ERRBUF_SIZE = 0;/* Retrieve the interfaces list */if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) = -1) fprintf(stderr,Error in pcap_findalldevs: %sn,errbuf); exit(1);/* Scan the list printing every entry */for(d=alldevs;d;d=d-next) ifprint(d);pcap_freealldevs(alldevs);return 1;/* Print all the available information on the given interface */void ifprint(pcap_if_t *d)pcap_addr_t *a;char ip6str128;/* Name */printf(%sn,d-name);/* Description */if (d-description) printf(tDescription: %sn,d-description);/* Loopback Address*/printf(tLoopback: %sn,(d-flags & PCAP_IF_LOOPBACK)?yes:no);/* IP addresses */for(a=d-addresses;a;a=a-next) printf(tAddress Family: #%dn,a-addr-sa_family); switch(a-addr-sa_family) case AF_INET: printf(tAddress Family Name: AF_INETn); if (a-addr) printf(tAddress: %sn,iptos(struct sockaddr_in *)a-addr)-sin_addr.s_addr); if (a-netmask) printf(tNetmask: %sn,iptos(struct sockaddr_in *)a-netmask)-sin_addr.s_addr); if (a-broadaddr) printf(tBroadcast Address: %sn,iptos(struct sockaddr_in *)a-broadaddr)-sin_addr.s_addr); if (a-dstaddr) printf(tDestination Address: %sn,iptos(struct sockaddr_in *)a-dstaddr)-sin_addr.s_addr); break; case AF_INET6: printf(tAddress Family Name: AF_INET6n); if (a-addr) printf(tAddress: %sn, ip6tos(a-addr, ip6str, sizeof(ip6str); break; default: printf(tAddress Family Name: Unknownn); break; printf(n);/* From tcptraceroute, convert a numeric IP address to a string */#define IPTOSBUFFERS 12char *iptos(u_long in)static char outputIPTOSBUFFERS3*4+3+1;static short which;u_char *p;p = (u_char *)∈which = (which + 1 = IPTOSBUFFERS ? 0 : which + 1);sprintf(outputwhich, %d.%d.%d.%d, p0, p1, p2, p3);return outputwhich;char* ip6tos(struct sockaddr *sockaddr, char *address
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年鹰潭辅警协警招聘考试真题含答案详解(完整版)
- 2025年随州辅警招聘考试真题附答案详解(轻巧夺冠)
- 2025年红河州辅警招聘考试真题及答案详解(全优)
- 2025年酒泉辅警协警招聘考试备考题库及答案详解(基础+提升)
- 2025年滨州辅警协警招聘考试备考题库含答案详解(达标题)
- 2025汽车销售提成合同
- 2025赠与合同无偿赠与合同的式样
- 2025年阿勒泰辅警招聘考试题库及完整答案详解1套
- 2025年韶关辅警协警招聘考试备考题库及一套参考答案详解
- 2025年石柱县辅警招聘考试题库附答案详解(能力提升)
- 小小牙医活动方案流程
- 低压断路器课件
- 中职学考《哲学与人生》考试复习题库(含答案)
- 人教版一年级上册道德与法治教案全册
- 老年人服务礼仪与沟通技巧
- 《社会性动物》读书分享
- 《试验数据统计分析》课件
- 林区施工防火安全施工方案
- 农业水利工程专业大学生职业生涯规划书
- 新概念第二册Lesson-41课件
- 云南省红河绿春X波段天气雷达建设项目环评报告
评论
0/150
提交评论