Windows下配置使用WinPcap
windows: win7 x64
WinPcap版本:4.1.3
WinPcap开发包:4.1.2
目标:在VS2010中配置使用winpcap 获取目标计算机中安装的网卡列表
http://www.winpcap.org/

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

配置头文件 和 库文件
项目属性--VC++目录--包含目录 / 库目录

获取本机 / 远程机器上网卡的列表和相关数据
/*******************************
函数成功返回 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 ;
}
本机测试

远程机器测试

Windows下配置使用WinPcap的更多相关文章
- windows 下配置 Nginx 常见问题(转)
windows 下配置 Nginx 常见问题 因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我 ...
- Windows下配置使用 MemCached
Windows下配置使用MemCached 工具: memcached-1.2.6-win32-bin.zip MemCached服务端程序(for win) Memcached Manage ...
- windows下配置wnmp
最近尝试windows下配置nginx+php+mysql,在这里总结一下. 1.下载windows版本的nginx,官网下载地址:http://nginx.org/en/download.htm, ...
- windows下配置lamp环境(5)---配置MySQL5.6
开始配置mysql 1.创建配置文件my.ini 1.进入C:\wamp\MySQL 2.把my-default.ini 另存一份:my.ini 3.开始编辑mysql的配置文件,打开my ...
- windows下配置lamp环境(3)---配置PHP5.4
下面配置php Php文件夹里有两个php.ini-*文件,随便修改一个,去掉后缀,变成php.ini (如图) 打开php.ini ,添加php扩展目录723行左右(其实放哪都无所谓,只不过php. ...
- windows下配置lamp环境(0)---软件获取
工作快一年了,还没有怎么配置过服务器环境,经常使用集成套件wampserver,为了复习配置wamp服务器 特意在虚拟机中测试安装步骤如下. 安装前步骤:下载软件.软件下载地址如下: 1.apache ...
- windows下配置lamp环境(2)---配置Apache服务器2.2.25
配置Apache 配置Apache时,先要找到安装目录中的主配置文httpd.conf,使用文本编辑器打开,最好不要使用windows自带的编辑器,可以使用NotePad++, vim,或者subli ...
- windows下配置svn的https访问
svn是一个功能强大的代码版本管理系统,可以将服务端安装在linux.unix以及windows下.svn通常采用http方式进行代码提交与下载.由于密码采用明文传输,因此存在泄密的风险.若采用htt ...
- windows下配置lamp环境(1)---安装Apache服务器2.2.25
window下lamp成为wamp; 安装wamp环境的第一步是安装Apache服务器.下面开始安装步骤图文并茂. 一.双击安装包点“next”进行下一步,然后同意协议(这张图没有截):
随机推荐
- SQL SERVER ->> Columnstore Index
谈到Columnstore index就不得不提SQL SERVER的压缩技术了.Columnstore就是用到了SQL SERVER的压缩技术.Columnstore又分Columnstore和Co ...
- 转 RMI、RPC、SOAP通信技术介绍及比对
http://www.open-open.com/home/space.php?uid=37924&do=blog&id=8974 1.RMI 使用java的程序员,对于RMI(Rem ...
- ubuntu启动eclipse时出错cannot open display
由于要学习hadoop,就在ubuntu下创建了一个hadoop用户,但是eclipse是在naomi用户下装的,在root和naomi用户下都能正常启动,但是一旦切换到hadoop用户,试着启动ec ...
- android sqlite 一次创建多个表
package com.yangguangfu.database; import android.content.Context; import android.database.sqlite.SQL ...
- Post的请求案例
1.简单的post请求案例 $.post(rootPath+"/jasframework/loginLog/getStatisticsInfoByUserId.do",functi ...
- Codeforces Round #215 (Div. 1) B
出来冒个泡 由于数比较大 开了map计数 然后边走边删边加 勉强可过 #include <iostream> #include<cstdio> #include<cs ...
- 转载 近期微博吐槽言论存档,涉及“性能优化”、C++陋习等
http://blog.csdn.net/solstice/article/details/9923615 近期微吐槽博言论存档,涉及“性能优化”.C++陋习等 写C++程序的几个陋习:class 名 ...
- ASP.NET26 个常用性能优化方法
数据库访问性能优化 数据库的连接和关闭 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源. ASP.NET中提供了连接池(Co ...
- HTTP使用BASIC认证的原理及实现方法
一. BASIC认证概述 在HTTP协议进行通信的过程中,HTTP协议定义了基本认证过程以允许HTTP服务器对WEB浏览器进行用户身份证的方法,当一个客户端向HTTP服务器进行数据请求时,如果客户 ...
- 谷歌的ajax.googleapis.com被墙导致访问很多国外网站很慢的解决方法
比如访问StackOverflow, 更比如flexerasoftware.com(导致Visual Studio的打包程序InstallShield Limited Edition不能注册和下载) ...