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;

来源:python脚本自动迁移

posted @ 2020-06-24 11:32  jiangcheng_15  阅读(228)  评论(0编辑  收藏  举报