VC中如何获取本地计算机MAC地址
6个回答
2013-07-27
展开全部
#include"stdafx.h"
#include
#include
#include"iphlpapi.h"
#pragmacomment(lib,"Iphlpapi.lib")
intmain(intargc,char*argv[])
{
PIP_ADAPTER_INFOpAdapterInfo;
PIP_ADAPTER_INFOpAdapter=NULL;
DWORDdwRetVal=0;
pAdapterInfo=(IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO));
ULONGulOutBufLen=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%sn",pAdapter->AdapterName);
printf("AdapterDesc:t%sn",pAdapter->Description);
printf("AdapterAddr:t");
for(UINTi=0;iAddressLength;i++)
{
printf("%02X%c",pAdapter->Address[i],
i==pAdapter->AddressLength-1?’n’:’-’);
}
printf("AdapterType:t%dn",pAdapter->Type);
printf("IPAddress:t%sn",pAdapter->IpAddressList.IpAddress.String);
printf("IPMask:t%sn",pAdapter->IpAddressList.IpMask.String);
}
pAdapter=pAdapter->Next;
}
}
else
{
printf("CalltoGetAdaptersInfofailed.n");
}
return0;
}
#include
#include
#include"iphlpapi.h"
#pragmacomment(lib,"Iphlpapi.lib")
intmain(intargc,char*argv[])
{
PIP_ADAPTER_INFOpAdapterInfo;
PIP_ADAPTER_INFOpAdapter=NULL;
DWORDdwRetVal=0;
pAdapterInfo=(IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO));
ULONGulOutBufLen=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%sn",pAdapter->AdapterName);
printf("AdapterDesc:t%sn",pAdapter->Description);
printf("AdapterAddr:t");
for(UINTi=0;iAddressLength;i++)
{
printf("%02X%c",pAdapter->Address[i],
i==pAdapter->AddressLength-1?’n’:’-’);
}
printf("AdapterType:t%dn",pAdapter->Type);
printf("IPAddress:t%sn",pAdapter->IpAddressList.IpAddress.String);
printf("IPMask:t%sn",pAdapter->IpAddressList.IpMask.String);
}
pAdapter=pAdapter->Next;
}
}
else
{
printf("CalltoGetAdaptersInfofailed.n");
}
return0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询