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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • C# WinForm界面美化插件简介

    C# WinForm界面美化插件简介 美化C#的WIN程序界面可以考虑用第三方控件,比如DotNetBar或DevExpress。但是它们都是收费的,虽然有破解版。。但是使用时还是需要权衡的。另外,用第三方控件会让运行速度下降。 1.      DevExpress收费软件 2.      Rad 3.      Irisskin2在项目中添加DLL文件,在程序中控制显示即可。使

    2022年5月8日
    120
  • 安卓framework面试题(高级Android面试题)

    Framework面试题 Android 系统基础 JVM、Dalvik和ART是什么以及他们的关系 01 Binder机制 02 系统级app和第三方应用级app分别在什么目录下?system/priva-app和system/app目录的权限有什么…

    2022年4月16日
    39
  • UDP协议的详细解析「建议收藏」

    UDP协议的详细解析「建议收藏」UDP数据报一、UDP的概述二、UDP的首部格式UDP校验

    2022年6月7日
    33
  • linux平均负载什么意思_负荷率和负载率一样吗

    linux平均负载什么意思_负荷率和负载率一样吗1,Linux系统的平均负载是什么?特定时间间隔内运行队列中的平均进程数,好象还不够明白:就是进程队列的长度,有多少个进程在排队等待运行2,什么是”进程队列”?一个进程满足以下条件就会位于进程队列中1,它没有在等待I/O操作的结果2,它没有主动进入等待状态(即没有调用wait)3,它没有被停止3,如何查看平均负载?最简单的命令是uptime例子:[www.linuxidc.com@localho…

    2022年9月2日
    6
  • IE重新装ActiveX控件[通俗易懂]

    IE重新装ActiveX控件[通俗易懂]项目因版本升级,需要重新安装一次已经装过的ActiveX控件,安装步骤如下: IE–&gt;右键属性–》程序–》管理加载项–&gt;IE已经使用的加载项–》找到原来安装的控件–》更新ActiveX(需要事先讲新控件放到相关文件夹)。 推荐使用:IE安装好的ActiveX控件存放在C:\WINDOWS\DownloadedProgramFiles,先删除…

    2022年5月14日
    45
  • 感谢 Gridea,让我有动力写作

    感谢 Gridea,让我有动力写作1.真的要感谢Gridea,让我对写作产生热忱。一直有在各大博客平台输出的习惯,但是都没有持续更新。有的平台广告太多,写不下去。有的平台排版复杂,写文章1个小时,排版要2个小时。所以后面换成了静态

    2022年8月3日
    9

发表回复

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

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