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”进行下一步,然后同意协议(这张图没有截):
随机推荐
- json 字符串转换成对象,对象转换成json字符串
json 字符串转换成对象,对象转换成json字符串 前端: 方法一: parseJSON方法: [注意jquery版本问题] var str = '{"name":&qu ...
- ubuntu下如何查看用户登录及系统授权相关信息【转】
转自:http://www.tuicool.com/articles/ia67Bj 如何在ubuntu下查看相关用户登录历史,进行系统的日志跟踪和分析,以便发现系统登录问题,进行安全策略防护呢?ubu ...
- 很实用的js限制不让输入其他字符,只让输入数字和 js生成UUID
onkeyup="this.value=this.value.replace(/\D/g,'')" js生产UUID var createUUID = (function (uui ...
- Python得到两个时间段的每一天的列表
date_list = [] begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d") end_date = ...
- Volley HTTP库系列教程(4)Volley内置的几种请求介绍及示例,StringRequest,ImageRequest,JsonObjectRequest
Making a Standard Request Previous Next This lesson teaches you to Request a String 返回String Requ ...
- SPOJ 422 Transposing is Even More Fun(polay计数)
题目链接:http://www.spoj.com/problems/TRANSP2/ 题意: 思路:不妨设a=1,b=2, 我们发现(001,010,100)组成一个置换,(011,110,101)组 ...
- c#换ip代理源码
很多朋友都想如何提高自己的网站流量,可是都没有什么好的办法 经过很长时间的研究,在C#中实现了,当然了,这部分代码其中一部分是网上的,不是原创. using System; using System. ...
- java socket编程基础
1. [代码]读操作Runable 1 package com.hrd.test.socket; import java.io.BufferedReader; import java.io.IOExc ...
- 非常非常非常好!path-sum-iii
https://leetcode.com/problems/path-sum-iii/ 最终我还是没做出好的解法.还是看的别人的解法. 即使看了别人的解法,开始还实现错了. 还有很长的路要走. pac ...
- String.indexOf()
int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引. int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次 ...