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语言标识符关键字_c语言标识符关键字有哪些

    C语言标识符关键字_c语言标识符关键字有哪些一、关键字1.什么是关键字关键字就是C语言提供的有特殊含义的符号,有些地方也叫做“保留字”。 2.一共有哪些关键字C语言一共提供了32个关键字,这些关键字都被C语言赋予了特殊含义。autodoubleintstructbreakelselongswitchcaseenumregistertypedefcharexternreturn

    2022年10月3日
    0
  • 什么是跨域?怎么解决跨域问题?「建议收藏」

    什么是跨域?怎么解决跨域问题?「建议收藏」什么是跨域?跨域,指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制。所谓同源是指,域名,协议,端口均相同,不明白没关系,举个栗子:http://www.123.com/index.html调用http://www.123.com/server.php(非跨域)http://www.123.com

    2022年6月13日
    23
  • sql的外连接包括_sql几种连接方式

    sql的外连接包括_sql几种连接方式简述SQL中的“外连接” 1、SQL中外连接分为三种:左外连接、右外连接、全外连接。2、英文书写格式:左外连接:LEFTOUTERJOIN(LEFTJOIN);右外连接:RIGHTOUTERJOIN(RIHTJOIN);全外连接:FULLOUTERJOIN(FULLJOIN)。3、简记:左外连接显示“左边全部的”和“右边与左边相同的”;右外

    2022年8月30日
    2
  • nginx根据url转发_nginx根据域名转发原理

    nginx根据url转发_nginx根据域名转发原理环境:centos:CentOSLinuxrelease7.6.1810(Core)nginx:1.15.8场景:在/home/centos/www下放有我们的项目,目前只能通过https://xxx.com/xxx访问项目,而我们想通过https://xxx.com/就能访问我们的项目。nginx配置如下:location/xxx{root/home/cen…

    2022年10月19日
    0
  • 在windows cgywinportable上,通过运行linux命令,批量改动文件名。

    在windows cgywinportable上,通过运行linux命令,批量改动文件名。

    2022年3月3日
    37
  • lefse分析本地实现方法带全部安装文件和所有细节,保证成功。

    lefse分析本地实现方法带全部安装文件和所有细节,保证成功。本人在win7-64和win10-64均完整安装使用,其他系统本人能力所限没安装成功。lefse本地分析包。()安装python2.7。()R语言3.6.1(这个应该是最新版就可以了应该无版本要求的,但我的是3.6.1就不提供下载地址了)这个是我总结的安装需求R语言:splines,stats4,survival,mvtnorm,modeltools,coin,MASS…

    2022年6月9日
    40

发表回复

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

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