当前位置: 首页 > 网络知识

Windows下配置使用WinPcap

时间:2026-01-29 09:27:06
0、前提

windows: win7 x64

WinPcap版本:4.1.3

WinPcap开发包:4.1.2

目标:在VS2010中配置使用winpcap 获取目标计算机中安装的网卡列表

1、下载

winpcap/

下载winpcap安装包 和 开发包

安装包安装完毕后,解压开发包到某个目录即可,开发包免安装。

3、在VS2010中配置

配置头文件 和 库文件

项目属性VC++目录包含目录 / 库目录

4、Demo

获取本机 / 远程机器上网卡的列表和相关数据

1 /******************************* 2 函数成功返回 0 3 失败返回  1 4 *******************************/ 5 int 6 pcap_findalldevs_ex( 7 char *source, //本机/远程机器/文件 8 struct pcap_rmtauth *auth, //目标机器用户名 密码 9 pcap_if_t **alldevs, //输出参数,详细信息 10 char *errbuf //缓冲区 大小为PCAP_BUF_SIZE,函数失败时保存错误信息 11 );
pcap_findalldevs_ex函数指定本机时指定参数"rpcap://" 或 预定义宏PCAP_SRC_IF_STRING
当指定远程机器时需要按照"rpcap://host:port"的格式,默认端口号为2002
远程机器有密码时需要指定用户名和密码。 1 struct pcap_rmtauth 2 ;
1 // demo1pp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <WinSock2.h> 7 #include <Windows.h> 8 9 //the macro HAVE_REMOTE must define before 10 #ifndef HAVE_REMOTE 11 #define HAVE_REMOTE 12 #endif 13 14 #include <pcap.h> 15 #include <remoteext.h> 16 17 #pragma cment(lib, "ws2_32.lib") 18 #pragma cment(lib, "packet.lib") 19 #pragma cment(lib, "wpcap.lib") 20 21 using namespace std; 22 23 24 /************************************************************************/ 25 /* platfor win7 x64 26 * version of winpcap: 4.1.3 27 * version of developping tool: 4.1.2 28 29 * notes: The local/remote machine must install the Winpcap 30 and 31 Start the server(go to the install path and double click rpcapd.exe). 32 33 You must look out that the DEFAULT PORT is 2002. 34 If you use another port, the pcap_findalldevs_ex function return 1 35 and the erro information in errbuf is 36 [Is the server properly installed on XXX.XXX.XXX.XXX? 37 connect() failed: 由于目标计算机积极拒绝,无法连接。 (code 10061) ] 38 39 /************************************************************************/ 40 41 int _tmain(int argc, _TCHAR* argv[]) 42 ; 47 stAuth.type = RPCAP_RMTAUTH_PWD; 48 stAuth.username = "xxxxx"; 49 stAuth.password = "xxxxxxxxxxx"; 50 51 pcap_if_t* pPcapIft = NULL; 52 char chBuffer[PCAP_BUF_SIZE] = ; 53 54 55 int nCount = 0; 56 57 if (0 == pcap_findalldevs_ex(pSource, &stAuth, &pPcapIft, chBuffer)) 58 87 88 89 psockAddr = (struct sockaddr_in*)(pAddr>dstaddr); 90 if (NULL != psockAddr) 91 98 99 100 101 102 psockAddr = (struct sockaddr_in*)(pAddr>broadaddr); 103 if (NULL != psockAddr) 104 110 111 112 psockAddr = (struct sockaddr_in*)(pAddr>dstaddr); 113 if (NULL != psockAddr) 114 119 120 cout << "" << endl << endl << endl; 121 122 } //for 123 124 125 } //for 126 127 128 pcap_freealldevs(pPcapIft); 129 130 } //if 131 else 132 136 137 system("pause"); 138 139 return 0; 140 }

5、运行结果

本机测试

远程机器测试



上一篇:Windows下安装配置WinPcap
下一篇:Qt QChart QValueAxis轴刻度用科学计数法表示、隐藏网格线
WinPcap
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素