词条 | GetAdaptersInfo |
释义 | 使用GetAdaptersInfo获取网卡详细信息(包括:Adapter Name,Mac,Ip,NetMask,NetGate) #include <winsock2.h> #include <iphlpapi.h> #include <stdio.h> #pragma comment(lib,"Iphlpapi.lib") int main() { // 初始化winsock PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO); pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen); DWORD dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen); // 第一次调用GetAdapterInfo获取ulOutBufLen大小 if (dwRetVal == ERROR_BUFFER_OVERFLOW) { free(pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen); } if (dwRetVal == NO_ERROR) { pAdapter = pAdapterInfo; while (pAdapter) { printf("Adapter Name: \\t%s\", pAdapter->AdapterName); printf("Adapter Desc: \\t%s\", pAdapter->Description); printf("MAC Addr: \\t%02x-%02x-%02x-%02x-%02x-%02x\", pAdapter->Address[0], pAdapter->Address[1], pAdapter->Address[2], pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]); printf("IP Address: \\t%s\", pAdapter->IpAddressList.IpAddress.String); printf("IP Mask: \\t%s\", pAdapter->IpAddressList.IpMask.String); printf("Gateway: \\t%s\", pAdapter->GatewayList.IpAddress.String); pAdapter = pAdapter->Next; }// end while } else { printf("Call to GetAdaptersInfo failed.\"); } ...卸载winsock ... return 0; } //end main |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。