• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > 利用C++程序獲取網卡的相關信息

    利用C++程序獲取網卡的相關信息

    作者: 時間:2010-09-14 來源:網絡 收藏

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

    本文引用地址:http://www.czjhyjcfj.com/article/151546.htm

      #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

      }



    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 恩平市| 连城县| 高唐县| 石屏县| 高青县| 南阳市| 常德市| 衡东县| 德江县| 夏津县| 司法| 探索| 札达县| 平塘县| 内乡县| 若羌县| 巩留县| 尤溪县| 宽城| 尤溪县| 闽清县| 古蔺县| 广汉市| 金乡县| 固原市| 宝鸡市| 长阳| 蓬安县| 东兰县| 庆元县| 江西省| 永清县| 克拉玛依市| 余庆县| 淮安市| 隆子县| 铁力市| 寿光市| 泗阳县| 郧西县| 如东县|