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


相关推荐

  • ubuntu clion 2020 永久激活码_通用破解码

    ubuntu clion 2020 永久激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    182
  • python在线编程平台-python在线编程

    python在线编程平台-python在线编程广告关闭腾讯云双 11 爆品提前享 精选热门产品助力上云 云服务器首年 88 元起 买的越多返的越多 最高满返 5000 元 python 并发编程的思维导图 原始文件请转到 processon 链接查看 io 模型阻塞 io 非阻塞 io io 多路复用 事件驱动 io 异步 io 本节课我们来学习一下 python 的模块编程模块是一个包含所有你定义的函数和变量的文件 其后缀名是 py 模块可以

    2025年11月28日
    4
  • 【实施工程师】ubuntu创建文件

    【实施工程师】ubuntu创建文件【实施工程师】ubuntu创建文件touch命令:touch文件名.后缀在当前工作目录底下新建一个文件:touchindex.php编辑文件使用【vi】或【vim】均可。键盘输入【i】是开始输入:输入测试内容:键盘输入【Esc+:wq】退出并保存查看是否编辑成功:保存成功。…

    2025年6月26日
    4
  • Codeforces 459E Pashmak and Graph(dp+贪婪)

    Codeforces 459E Pashmak and Graph(dp+贪婪)

    2022年1月5日
    44
  • np.astype()

    np.astype()1.作用:就是转换numpy数组的数据类型举个例子arr=np.arange((10))print(arr,arr.dtype,sep=”\n”)===================================[0123456789]int32#可以看到,他的数据类型为int32np.astype()arr=arr.astype(“f…

    2022年6月10日
    50
  • 阿里云设置端口访问、使用_阿里云服务器端口号

    阿里云设置端口访问、使用_阿里云服务器端口号登录阿里云账号后,点击控制台点击自定义视图→再点击云服务器ECS点击实例id进入实例:点击本实例安全组:点击安全组id或者配置规则进入安全组规则配置界面,可以选择添加方式,这里以手动添加作为演示点击手动添加后,会出现添加栏,我们配置521端口,源选择0.0.0.0/0(意思是开放给所有人),最后点击保存放行端口就设置完毕了此外也可以从另一个地方进入本地实例安全组:(1)点击云服务器ECS后(上述步骤3)进入实例页面后,可以直接点击实例(2)选择自..

    2022年10月3日
    2

发表回复

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

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