跳至内容
深圳市捷比信实业有限公司 · 产品选型与采购咨询联系业务人员
抗浪涌电阻捷比信 · 专业器件主题站

C ++源代码,用于获取有关网卡的信息

///////////////////////////////////////////////////// ////////////// ## include& quot; stdafx.h& quot; #include #include #include" Iphlpapi.h& quot;使用命名空间std; PIP_ADAPTER_INFO pinfo = NULL; unsigned long len = 0; CString macaddress; CString描述; CString type; CString子网; CString IpAddress; CString gateway; CString PrimaryWinsServer; CString dhcp;无效的GetInfo(); void ParseData();无效的OutPut(CString str); void main(){cout& lt;& quot;“ ------------------------网卡信息检测------ --------------- n& quot ;;获取信息(); }避免GetInfo(){if(pinfo!= NULL)删除(pinfo); unsigned long nError; nError = GetAdaptersInfo(pinfo,& len); // 1 ??& uuml;oˉ& ecirc; y if(nError == 0){ParseData(); } if(nError == ERROR_NO_DATA){OutPut(& quot;没有网络设备信息& quot)); } if(nError == ERROR_NOT_SUPPORTED){OutPut(&“ GetAdaptersInfo不支持本系统")); } if(nError == ERROR_BUFFER_OVERFLOW){pinfo =(PIP_ADAPTER_INFO)malloc(len); nError = GetAdaptersInfo(pinfo,& len);如果(nError == 0){ParseData(); } } 返回; }避免ParseData(){if(pinfo!= NULL){macaddress.Format("%02X:%02X:%02X:%02X:%02X:%02X& quot; pinfo-& gt;地址[0],pinfo-& gt;地址[1],pinfo-& gt;地址[2],pinfo-& gt;地址[3],pinfo->地址[4],pinfo- & gt;地址[5]); description = pinfo-& gt;说明; type.Format(&“%d&”,pinfo-& gt; Type); PIP_ADDR_STRING pAddressList =&(pinfo-> IpAddressList); IpAddress =&“&” ;; do {IpAddress + = pAddressList-& gt; IpAddress.String; pAddressList = pAddressList->下一步; if(pAddressList!= NULL)IpAddress + =&“ rn&”; } while(pAddressList!= NULL); subnet.Format(&“%s&”,pinfo-& gt; IpAddressList.IpMask.String); gateway.Format(&“%s&”,pinfo-& gt; GatewayList.IpAddress.String); if(pinfo-> HaveWins)sPrimaryWinsServer.Format(&“%s&”,pinfo-> PrimaryWinsServer.IpAddress.String); else PrimaryWinsServer.Format(&“%s&”,&“ N / A&”); if(pinfo-& gt; DhcpEnabled)dhcp.Format(&“%s&”,pinfo-> DhcpServer.IpAddress.String); else dhcp.Format(&“%s&”,& N / A& N); pinfo = pinfo-& gt; Next; } OutPut(&“网络设备为:t& quot; +说明); OutPut(&“ Mac地址为:t&” + macaddress); OutPut(&“网卡类型:t&” + type); OutPut(&“ IP地址:t&” + IpAddress); OutPut(& quot;子网:t& quot; + subnet); OutPut(&“网关:t&” + gateway); OutPut(&“主WinsServer:t&” + PrimaryWinsServer); OutPut(&“ dhcp服务器:t&” + dhcp); }避免OutPut(CString str){cout& lt; }