利用C++程序获取网卡的相关信息

#include "stdafx.h"

#include

#include

#include "Iphlpapi.h"

using namespace std;

PIP_ADAPTER_INFO pinfo=NULL;

unsigned long len=0;

CString macaddress;

CString  description;

CString  type;

CString  subnet;

CString  IpAddress;

CString  gateway;

CString  PrimaryWinsServer;

CString  dhcp;

void GetInfo();

void ParseData();

void OutPut(CString str);

void main()

{

cout<<"------------------------网卡信息检测---------------------n";

GetInfo();

}

void GetInfo()

{

if (pinfo!=NULL)

delete (pinfo);

unsigned long nError;

nError  =  GetAdaptersInfo(pinfo,&len); //1??üoˉêy

if (nError==0)

{

ParseData();

}

if (nError==ERROR_NO_DATA)

{

OutPut("没有网络设备信息");

}

if (nError==ERROR_NOT_SUPPORTED)

{

OutPut("GetAdaptersInfo不支持本系统");

}

if (nError==ERROR_BUFFER_OVERFLOW)

{

pinfo= (PIP_ADAPTER_INFO)malloc(len);

nError  =  GetAdaptersInfo(pinfo,&len);

if (nError==0)

{

ParseData();

}

}

return;

}

void ParseData()

{

if (pinfo!=NULL)

{

macaddress.Format("%02X:%02X:%02X:%02X:%02X:%02X",pinfo->Address[0],pinfo->Address[1],pinfo->Address[2],pinfo->Address[3],pinfo->Address[4],pinfo->Address[5]);

description  =  pinfo->Description;

type.Format("%d",pinfo->Type);

PIP_ADDR_STRING pAddressList = &(pinfo->IpAddressList);

IpAddress  ="";

do

{

IpAddress  +=  pAddressList->IpAddress.String;

pAddressList = pAddressList->Next;

if (pAddressList != NULL)

IpAddress  +="rn";

} while (pAddressList != NULL);

subnet.Format("%s",pinfo->IpAddressList.IpMask.String);

gateway.Format("%s",pinfo->GatewayList.IpAddress.String);

if (pinfo->HaveWins)

PrimaryWinsServer.Format("%s",pinfo->PrimaryWinsServer.IpAddress.String );

else

PrimaryWinsServer.Format("%s","N/A" );

if (pinfo->DhcpEnabled )

dhcp.Format("%s",pinfo->DhcpServer.IpAddress.String );

else

dhcp.Format("%s","N/A");

pinfo = pinfo->Next;

}

OutPut("网络设备为:t"+description);

OutPut("Mac地址为:t"+macaddress);

OutPut("网卡类型:t"+type);

OutPut("IP地址:t"+IpAddress);

OutPut("子网掩码:t"+subnet);

OutPut("网关:t"+gateway);

OutPut("主Wins服务器:t"+PrimaryWinsServer);

OutPut("dhcp服务器:t"+dhcp);

}

void OutPut(CString str)

{

cout<

}

来源:21IC电子网


微信扫描分享本文到朋友圈
扫码关注5G通信官方公众号,免费领取以下5G精品资料
  • 1、回复“LTBPS”免费领取《《中国联通5G终端白皮书》
  • 2、回复“ZGDX”免费领取《中国电信5GNTN技术白皮书
  • 3、回复“TXSB”免费领取《通信设备安装工程施工工艺图解
  • 4、回复“YDSL”免费领取《中国移动算力并网白皮书
  • 5、回复“5GX3”免费领取《R1623501-g605G的系统架构1
  • 7、回复“6G31”免费领取《基于云网融合的6G关键技术白皮书
  • 8、回复“IM6G”免费领取《6G典型场景和关键能力白皮书
  • 本周热点本月热点

     

      最热通信招聘

      最新招聘信息

    最新技术文章

    最新论坛贴子