目前主要从事C++软件开发
分类: C/C++
2013-01-30 11:37:07
#include "stdafx.h" #include#include #include"iphlpapi.h" # pragma comment(lib,"Iphlpapi.lib") int _tmain(int argc, _TCHAR* argv[]) { PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter=NULL; DWORD dwRetVal=0; pAdapterInfo=(IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO)); ULONG ulOutBufLen=sizeof(IP_ADAPTER_INFO); if(GetAdaptersInfo(pAdapterInfo,&ulOutBufLen)!=ERROR_SUCCESS){ GlobalFree(pAdapterInfo); pAdapterInfo=(IP_ADAPTER_INFO*)malloc(ulOutBufLen); } if((dwRetVal=GetAdaptersInfo(pAdapterInfo,&ulOutBufLen))==NO_ERROR){ pAdapter=pAdapterInfo; while(pAdapter){ if(strstr(pAdapter->Description,"PCI")>0//pAdapter->Description中包含"PCI"为:物理网卡 ||pAdapter->Type==71//pAdapter->Type是71为:无线网卡 ){ printf("------------------------------------------------------------\n"); printf("AdapterName:\t%s\n",pAdapter->AdapterName); printf("AdapterDesc:\t%s\n",pAdapter->Description); printf("AdapterAddr:\t"); for(UINT i=0;i AddressLength;i++){ printf("%02X%c",pAdapter->Address[i], i==pAdapter->AddressLength-1? '\n':'-'); } printf("AdapterType:\t%d\n",pAdapter->Type); printf("IPAddress:\t%s\n",pAdapter->IpAddressList.IpAddress.String); printf("IPMask:\t%s\n",pAdapter->IpAddressList.IpMask.String); } pAdapter=pAdapter->Next; } } else { printf("Call to Get Adapters Information failed\n"); } return 0; }