VC 获取多个mac地址
转载请注明来源:https://www.cnblogs.com/hookjc/
#include <IPHlpApi.h>#include <iostream>
#pragma comment ( lib, "Iphlpapi.lib")
using namespace std;
char mac[255]={0};
PIP_ADAPTER_INFO pIpAdapterInfo=new IP_ADAPTER_INFO();
unsigned long stSize=sizeof(IP_ADAPTER_INFO);
int nRel=GetAdaptersInfo(pIpAdapterInfo,&stSize);
if(ERROR_BUFFER_OVERFLOW==nRel)
{
delete pIpAdapterInfo;
pIpAdapterInfo=(PIP_ADAPTER_INFO)new BYTE[stSize];
nRel=GetAdaptersInfo(pIpAdapterInfo,&stSize);
}
if (ERROR_SUCCESS==nRel)
{
//输出网卡信息
while (pIpAdapterInfo)
{
sprintf(mac,"%s%02X-%02X-%02X-%02X-%02X-%02X",mac,
pIpAdapterInfo->Address[0],
pIpAdapterInfo->Address[1],
pIpAdapterInfo->Address[2],
pIpAdapterInfo->Address[3],
pIpAdapterInfo->Address[4],
pIpAdapterInfo->Address[5]);
pIpAdapterInfo = pIpAdapterInfo->Next;
}
}
//释放内存空间
if (pIpAdapterInfo)
{
delete pIpAdapterInfo;
}
cout<<mac<<endl;