您当前的位置:五五电子网电子知识单片机-工控设备嵌入式系统-技术利用C++程序获取网卡的相关信息 正文
利用C++程序获取网卡的相关信息

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

点击数:7172 次   录入时间:03-04 11:56:46   整理:http://www.55dianzi.com   嵌入式系统-技术

 //////////////////////////////////////////////////////////////////

  #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<

  }




本文关键字:程序  信息  网卡  嵌入式系统-技术单片机-工控设备 - 嵌入式系统-技术