windows配置与管理_win7卡在配置windows

windows配置与管理_win7卡在配置windows0、前提windows:win7x64WinPcap版本:4.1.3WinPcap开发包:4.1.2目标:在VS2010中配置使用winpcap获取目标计算机中安装的网卡列表1、下载h

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

 

 0、前提

     windows: win7 x64

     WinPcap版本:4.1.3

     WinPcap开发包:4.1.2

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

 

 1、下载

    http://www.winpcap.org/

 

    windows配置与管理_win7卡在配置windows

 

 

    下载winpcap安装包 和 开发包

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

    windows配置与管理_win7卡在配置windows

 

 

 3、在VS2010中配置

 

    配置头文件 和 库文件

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

    windows配置与管理_win7卡在配置windows

    

 

 

 

 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 = {0};
    stAuth.type = RPCAP_RMTAUTH_PWD;     
    stAuth.username = "xxxxx";
    stAuth.password = "xxxxxxxxxxx";

    pcap_if_t* pPcapIft = NULL;
    char chBuffer[PCAP_BUF_SIZE] = {0};

    
    int nCount = 0;

    if (0 == 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 0;
}

 

    

 

 5、运行结果

     

     本机测试

     windows配置与管理_win7卡在配置windows

 

 

    远程机器测试

    windows配置与管理_win7卡在配置windows

 

  

  

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/166601.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • PHP安装包TS和NTS的区别-Centos7 LANMP环境搭建(最完善版本)

    PHP安装包TS和NTS的区别-Centos7 LANMP环境搭建(最完善版本)

    2022年2月17日
    49
  • 按位异或解题技巧「建议收藏」

    按位异或解题技巧「建议收藏」按位异或可以解决类似开灯问题一类的问题。首先了解下什么是按位异或:异或运算:首先异或表示当两个数的二进制表示,进行异或运算时,当前位的两个二进制表示不同则为1相同则为0.该方法被广泛推广用来统计一个数的1的位数!参与运算的两个值,如果两个相应bit位相同,则结果为0,否则为1。即:  0^0=0,  1^0=1,  0^1=1,  1^1=0按位异或的3个特点:…

    2022年6月4日
    38
  • 高通QXDM_log工具怎么使用

    高通QXDM_log工具怎么使用https://blog.csdn.net/u010164190/article/details/79913808

    2022年9月26日
    0
  • Eurake[通俗易懂]

    Eurake[通俗易懂]eureka-core模块包含了功能的核心实现:1.com.netflix.eureka.cluster-与peer节点复制(replication)相关的功能2.com.netflix.eureka.lease-即”租约”,用来控制注册信息的生命周期(添加、清除、续约)3.com.netflix.eureka.registry-存储、查询服务注册信息4.com.n…

    2022年6月13日
    36
  • Linux虚拟机联网设置详细教程[通俗易懂]

    Linux虚拟机联网设置教程小伙伴们,你们在使用linux期间,是否遇到过需要联网的需求呢。这是一篇教你如何把Linux系统接入互联网的教程,本文介绍了两种联网的方式,适用的场景略有不同,每一种方法的优缺点会在文档中说明,请根据实际环境,自行选择,希望本文能帮助到你。一.环境介绍硬件:联想台式机软件:vmwareworkstation15pro操作系统:Centos7.9二.优缺点对比方法优点缺点桥接模式局域网内,与物理机处于同等位置,占用独立的局域网IP地址

    2022年4月12日
    62
  • 跳跃表(skiplist )详解及其C++编程实现

    跳跃表(skiplist )详解及其C++编程实现跳表SkipList跳表SkipList1、背景2、定义2.1、SkipList基本数据结构及其实现3、实现4、使用方法4.1、跳表的创建4.2、跳表插入操作参考跳表SkipList1、背景为什么选择跳表?目前经常使用的平衡数据结构有:B树,红黑树,AVL树,SplayTree,Treep等。跳表是平衡树的一种替代的数据结构,但是和红黑树不相同的是,跳表对于树的平衡的实现是基于一种随机化的算法的,这样也就是说跳表的插入和删除的工作是比较简单的。用跳表吧,跳表是一种随机化的数据结构,目前开源软件

    2022年10月19日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号