获取Mac地址
netapi32.lib
#include <NB30.h>; typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; }ASTAT, *PASTAT; void GetNetCardMac(int lana_num, char *pszOut) { NCB ncb; UCHAR uRetCode; ASTAT Adapter; memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBRESET; ncb.ncb_lana_num = lana_num; uRetCode = Netbios(&ncb); memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBASTAT; ncb.ncb_lana_num = lana_num; //Ö¸¶¨Íø¿¨ºÅ strcpy((char *)ncb.ncb_callname, "* "); ncb.ncb_buffer = (unsigned char *)&Adapter; ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios(&ncb); if (uRetCode == 0) { sprintf(pszOut, "%02X%02X%02X%02X%02X%02X", Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); //strcpy(pszOut, "00E04C0F7847"); //strcpy(pszOut, "00E04C0F783C"); } } void GetCardInfo(int iIdx, char *pszMac) { NCB ncb; UCHAR uRetCode; LANA_ENUM lana_enum; memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBENUM; ncb.ncb_buffer = (unsigned char *)&lana_enum; ncb.ncb_length = sizeof(lana_enum); uRetCode = Netbios(&ncb); for (int i = 0; i < lana_enum.length; ++i) { if (i == iIdx) { GetNetCardMac(lana_enum.lana[i], pszMac); } } }