MacAddr
调用系统接口获取网卡物理地址。
#include <windows.h>
#include <nb30.h>
#include <stdio.h>#pragma comment(lib, "Netapi32")
typedef struct _ASTAT_ {
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, * PASTAT;ASTAT Adapter;
int main (void) {
NCB Ncb;
UCHAR uRetCode;
LANA_ENUM lenum;
int i;memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (UCHAR *)&lenum;
Ncb.ncb_length = sizeof(lenum);
uRetCode = Netbios( &Ncb );for(i=0; i < lenum.length ;i++) {
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = lenum.lana[i];uRetCode = Netbios(&Ncb);
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = lenum.lana[i];strcpy((char*)Ncb.ncb_callname, "* ");
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof(Adapter);uRetCode = Netbios(&Ncb);
if(uRetCode == 0) {
printf("Ethernet[%d] MacAddress:%02x%02x%02x%02x%02x%02x\n",
i,
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]);
}
}
return 0;
}