0、前提

windows: win7 x64

WinPcap版本:4.1.3

WinPcap开发包:4.1.2

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

 1、下载

http://www.winpcap.org/

下载winpcap安装包 和 开发包

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

 3、在VS2010中配置

配置头文件 和 库文件

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

 4、Demo

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

/*******************************
函数成功返回 0
失败返回  -1
*******************************/
int
pcap_findalldevs_ex(
char *source, //本机/远程机器/文件
struct pcap_rmtauth *auth, //目标机器用户名 密码
pcap_if_t **alldevs, //输出参数,详细信息
char *errbuf //缓冲区 大小为PCAP_BUF_SIZE,函数失败时保存错误信息
);
pcap_findalldevs_ex函数指定本机时指定参数"rpcap://" 或 预定义宏PCAP_SRC_IF_STRING
当指定远程机器时需要按照"rpcap://host:port"的格式,默认端口号为2002
远程机器有密码时需要指定用户名和密码。
struct pcap_rmtauth
{ int type; //#define RPCAP_RMTAUTH_NULL 0 或 用户名密码验证 #define RPCAP_RMTAUTH_PWD 1 char *username; //用户名 char *password; //密码
};
// demo1.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <WinSock2.h>
#include <Windows.h> //the macro HAVE_REMOTE must define before
#ifndef HAVE_REMOTE
#define HAVE_REMOTE
#endif #include <pcap.h>
#include <remote-ext.h> #pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "packet.lib")
#pragma comment(lib, "wpcap.lib") using namespace std; /************************************************************************/
/* platfor win7 x64
* version of winpcap: 4.1.3
* version of developping tool: 4.1.2 * notes: The local/remote machine must install the Winpcap
and
Start the server(go to the install path and double click rpcapd.exe). You must look out that the DEFAULT PORT is 2002.
If you use another port, the pcap_findalldevs_ex function return -1
and the erro information in errbuf is
[Is the server properly installed on XXX.XXX.XXX.XXX?
connect() failed: 由于目标计算机积极拒绝,无法连接。 (code 10061) ] /************************************************************************/ int _tmain(int argc, _TCHAR* argv[])
{
//char* pSource = "rpcap://"; //localhost
char* pSource = "rpcap://XXX.XXX.XXX.XXX:2002"; //remote PC struct pcap_rmtauth stAuth = {};
stAuth.type = RPCAP_RMTAUTH_PWD;
stAuth.username = "xxxxx";
stAuth.password = "xxxxxxxxxxx"; pcap_if_t* pPcapIft = NULL;
char chBuffer[PCAP_BUF_SIZE] = {}; int nCount = ; if ( == pcap_findalldevs_ex(pSource, &stAuth, &pPcapIft, chBuffer))
{
for (pcap_if_t* pcap = pPcapIft; pcap != NULL; pcap = pcap->next)
{
cout << endl << "----------- device "
<< nCount ++
<< " -------------" << endl; cout << pcap->name
<< endl
<< pcap->description
<< endl
<< pcap->flags
<< endl; cout << "-------- Output details below -----" << endl; for (struct pcap_addr* pAddr = pcap->addresses;
pAddr != NULL; pAddr = pAddr->next)
{ struct sockaddr_in* psockAddr = (struct sockaddr_in*)(pAddr->addr);
if (NULL != psockAddr)
{
cout << "IP is " << inet_ntoa(psockAddr->sin_addr) << endl;
cout << "Port is " << ntohs(psockAddr->sin_port) << endl;
cout << "Family is " << psockAddr->sin_family << endl; cout << "-------" << endl;
} psockAddr = (struct sockaddr_in*)(pAddr->dstaddr);
if (NULL != psockAddr)
{
cout << "Mask IP is " << inet_ntoa(psockAddr->sin_addr) << endl;
cout << "Mask Port is " << ntohs(psockAddr->sin_port) << endl;
cout << "Mask Family is " << psockAddr->sin_family << endl; cout << "-------" << endl;
} psockAddr = (struct sockaddr_in*)(pAddr->broadaddr);
if (NULL != psockAddr)
{
cout << "Broadcast IP is " << inet_ntoa(psockAddr->sin_addr) << endl;
cout << "Broadcast Port is " << ntohs(psockAddr->sin_port) << endl;
cout << "Broadcast Family is " << psockAddr->sin_family << endl; } psockAddr = (struct sockaddr_in*)(pAddr->dstaddr);
if (NULL != psockAddr)
{
cout << "P2P IP is " << inet_ntoa(psockAddr->sin_addr) << endl;
cout << "P2P Port is " << ntohs(psockAddr->sin_port) << endl;
cout << "P2P Family is " << psockAddr->sin_family << endl;
} cout << "---------------------------------------" << endl << endl << endl; } //for } //for pcap_freealldevs(pPcapIft); } //if
else
{
cerr << endl << "Last error is " << GetLastError() << endl
<< chBuffer << endl;
} system("pause"); return ;
}
 5、运行结果

本机测试

远程机器测试

Windows下配置使用WinPcap的更多相关文章

  1. windows 下配置 Nginx 常见问题(转)

    windows 下配置 Nginx 常见问题 因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我 ...

  2. Windows下配置使用 MemCached

    Windows下配置使用MemCached 工具: memcached-1.2.6-win32-bin.zip     MemCached服务端程序(for win) Memcached Manage ...

  3. windows下配置wnmp

    最近尝试windows下配置nginx+php+mysql,在这里总结一下. 1.下载windows版本的nginx,官网​下载地址:http://nginx.org/en/download.htm, ...

  4. windows下配置lamp环境(5)---配置MySQL5.6

    开始配置mysql 1.创建配置文件my.ini   1.进入C:\wamp\MySQL   2.把my-default.ini 另存一份:my.ini   3.开始编辑mysql的配置文件,打开my ...

  5. windows下配置lamp环境(3)---配置PHP5.4

    下面配置php Php文件夹里有两个php.ini-*文件,随便修改一个,去掉后缀,变成php.ini (如图) 打开php.ini ,添加php扩展目录723行左右(其实放哪都无所谓,只不过php. ...

  6. windows下配置lamp环境(0)---软件获取

    工作快一年了,还没有怎么配置过服务器环境,经常使用集成套件wampserver,为了复习配置wamp服务器 特意在虚拟机中测试安装步骤如下. 安装前步骤:下载软件.软件下载地址如下: 1.apache ...

  7. windows下配置lamp环境(2)---配置Apache服务器2.2.25

    配置Apache 配置Apache时,先要找到安装目录中的主配置文httpd.conf,使用文本编辑器打开,最好不要使用windows自带的编辑器,可以使用NotePad++, vim,或者subli ...

  8. windows下配置svn的https访问

    svn是一个功能强大的代码版本管理系统,可以将服务端安装在linux.unix以及windows下.svn通常采用http方式进行代码提交与下载.由于密码采用明文传输,因此存在泄密的风险.若采用htt ...

  9. windows下配置lamp环境(1)---安装Apache服务器2.2.25

    window下lamp成为wamp; 安装wamp环境的第一步是安装Apache服务器.下面开始安装步骤图文并茂. 一.双击安装包点“next”进行下一步,然后同意协议(这张图没有截):

随机推荐

  1. Android百度地图开发04之POI检索

    POI检索 POI~~~ Point of Interest,翻译过来就是“兴趣点”.我们在使用地图的时候,搜索周边的ktv,饭店,或者宾馆的时候,输入关键字,然后地图展示给我们很多个点, 这些点就是 ...

  2. SQL Server ->> GROUPING SETS, CUBE, ROLLUP, GROUPING, GROUPING_ID

    在我们制作报表的时候常常需要分组聚合.多组聚合和总合.如果通过另外的T-SQL语句来聚合难免性能太差.如果通过报表工具的聚合功能虽说比使用额外的T-SQL语句性能上要好很多,不过不够干脆,还是需要先生 ...

  3. 机器人学 —— 轨迹规划(Configuration Space)

    之前的轨迹规划中,我们只考虑了质点,没有考虑机器人的外形与结构.直接在obstacle map 中进行轨迹规划,然而世纪情况中,机器人有固定外形,可能会和障碍物发生碰撞.此情况下,我们针对机器人自由度 ...

  4. code manager tools TotoiseSVN安装及使用

    TotoiseSVN安装及使用 TotoiseSVN官方下载地址:http://tortoisesvn.net/downloads.html TotoiseSVN安装:很简单,一路直下:就不在这说了, ...

  5. gitlab的搭建和linux客户端的连接

    一.安装 1.新建 /etc/yum.repos.d/gitlab-ce.repo,添加以下内容 1 2 3 4 5 6 7 [gitlab-ce] name=gitlab-ce baseurl=ht ...

  6. Nand flash uboot 命令详解【转】

    转自:http://blog.chinaunix.net/uid-14833587-id-76513.html nand info & nand device 显示flash的信息: DM36 ...

  7. Ubuntu对FireFox安装flash插件

    有时候我们需要在Ubuntu下采用手动安装一些软件,比如Firefox的Flash插件.Adobe® Flash® Player 是一款轻量级浏览器插件,具有丰富的 Internet 应用运行时间,提 ...

  8. SQL Server Object Explorer in VS

    菜单栏View-->SQL Server Object Explorer 默认有几个连接,可以根据需要自己再另外添加 比如添加127.0.0.1 建立连接之后,剩下的操作和sql server中 ...

  9. [HDOJ2602]Bone Collector(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 裸的... #include <algorithm> #include <io ...

  10. 等额本息Vs等额本金

    1:贷款种类一旦选择不能改变.2:你提前还款的全部属于本金部分,若能一次性归还本金只需付清当月月息即可[不按年利率计算而是月利率],与你归还的本金违约金[设:提前还款10万*X.XXX%=违约金,具体 ...