/*
只获取本地连接的网卡信息,并不获取无线网卡和虚拟网卡的信息,要想获取无线网卡的信息,需把if(strstr(pAdapter->Description,"PCI")>0 && pAdapter- >Type==MIB_IF_TYPE_ETHERNET)改成if(strstr(pAdapter->Type==71),若要获取虚拟网卡的信息,需把if(strstr(pAdapter->Description,"PCI")>0 && pAdapter->Type==MIB_IF_TYPE_ETHERNET)改成if(pAdapter->Type==MIB_IF_TYPE_ETHERNET)
*/
#include "stdafx.h"
#include <atlbase.h>
#include <atlconv.h>
#include "iphlpapi.h"
#pragma comment(lib,"Iphlpapi.lib")
int main()
{
PIP_ADAPTER_INFO pAdapterInfo=NULL;
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->Type==MIB_IF_TYPE_ETHERNET)
{
printf("______________________________________\n");
printf("Name:%s\n",pAdapter->AdapterName);
printf("Desc:%s\n",pAdapter->Description);
for(UINT i=0;i<pAdapter->AddressLength;i++)
{
printf("%02X%c",pAdapter->Address[i],i==pAdapter->AddressLength-1?‘\n‘:‘-‘);
}
printf("Type:%d\n",pAdapter->Type);
printf("Address:%s\n",pAdapter->IpAddressList.IpAddress.String);
printf("Mask:%s\n",pAdapter->IpAddressList.IpMask.String);
printf("Gateway:%s\n",pAdapter->GatewayList.IpAddress.String);
}
pAdapter=pAdapter->Next;
}
}
else
printf("Call to GetAdaptersInfo failed!\n");
return 0;
}
时间: 2024-12-28 21:18:48