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. Linux 关机命令详解

    在linux下一些常用的关机/重启命令有shutdown.halt.reboot.及init,它们都可以达到重启系统的目的,但每个命令的内部工作过程是不同的,通过本文的介绍,希望你可以更加灵活的运用各 ...

  2. JavaScript获取DOM元素位置和尺寸大小

      在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽略的一部分,要想写出预想效果的JavaScri ...

  3. PowerDesigner-自定义生成WORD

    PowerDesigner-自定义生成WORD_旧梦重温 分类: web 2014-02-26 21:08 1563人阅读 评论(48) 收藏 举报   目录(?)[+] 1统一建立模型 2导出自定义 ...

  4. 计算机IT求职学习List

    1. 算法相关 1.1 <编程珠玑> 1.2 <编程之美> 这两本是最经典的了,这里面注重的是解决问题的思路,看的时候里面的问题要认真思考再参考解答.下面两本是对具体的面试题做 ...

  5. CodeSmith连接Mysql配置

    1,首先需要将MySql.Data.dll复制到codesmith安装目录下v6.5/bin文件夹下,注意dll的版本 2,其次采用的是.net4.0的配置文件,找到C:\Windows\Micros ...

  6. Scorm 1.2 开发文档

    原文出处 电华教育研究杂志2010年第7期<SCORM标准学习跟踪机制的研究与实现> http://blog.sina.com.cn/s/blog_964ec55001014nl0.htm ...

  7. 如何添加或删除ubuntu用户和组【转】

    转自:http://blog.csdn.net/sin90lzc/article/details/7525670 在创建用户时,需要为新建用户指定一用户组,如果不指定其用户所属的工作组,自动会生成一个 ...

  8. windows服务删除后,在次安装时无法安装启动。

    当我在windows的cmd下卸载evtsys evtsys -u  再次安装时evtsys.exe -i -h 192.168.32.12 -p 514 提示“指定的服务已标记为删除”,进入服务管理 ...

  9. lightOJ 1366 Pair of Touching Circles(统计矩形内相切圆对)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:给出一个矩形,在内部画两个圆A和B使得AB都完全在矩形内且AB相切且AB的 ...

  10. Server Profiler

    Server Profiler 2014-10-31 工作原理 SQL Server Profiler这个工具是SQL Trace的一个GUI的版本,而SQL Trace是一组脚本,自SQL Serv ...