获取 Mac 地址 (VC)

Posted IT-渡子腾

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取 Mac 地址 (VC)相关的知识,希望对你有一定的参考价值。

 1 int getMAC(char * mac)     
 2 {     
 3     NCB ncb;     
 4     LANA_ENUM lana_enum;
 5     UCHAR uRetCode;
 6     memset(&ncb, 0, sizeof(ncb));
 7     memset(&lana_enum, 0, sizeof(lana_enum));
 8     ncb.ncb_command = NCBENUM;
 9     ncb.ncb_buffer = (unsigned char *)&lana_enum;
10     ncb.ncb_length = sizeof(LANA_ENUM);
11     uRetCode = Netbios(&ncb);
12     if(uRetCode != NRC_GOODRET)     
13         return uRetCode;     
14     for(int lana=0; lana<lana_enum.length; lana++)     
15     {
16         ncb.ncb_command = NCBRESET;
17         ncb.ncb_lana_num = lana_enum.lana[lana];
18         uRetCode = Netbios(&ncb);
19         if(uRetCode == NRC_GOODRET)
20             break; 
21     } 
22     if(uRetCode != NRC_GOODRET)
23         return uRetCode;     
24     memset(&ncb, 0, sizeof(ncb));
25     ncb.ncb_command = NCBASTAT;
26     ncb.ncb_lana_num = lana_enum.lana[0];
27     strcpy((char*)ncb.ncb_callname, "*");
28     ncb.ncb_buffer = (unsigned char *)&Adapter;
29     ncb.ncb_length = sizeof(Adapter);
30     uRetCode = Netbios(&ncb);
31     if(uRetCode != NRC_GOODRET)
32         return uRetCode;
33     sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
34         Adapter.adapt.adapter_address[0],
35         Adapter.adapt.adapter_address[1],
36         Adapter.adapt.adapter_address[2],
37         Adapter.adapt.adapter_address[3],
38         Adapter.adapt.adapter_address[4],
39         Adapter.adapt.adapter_address[5]);
40     return 0;   
41 } 

 

以上是关于获取 Mac 地址 (VC)的主要内容,如果未能解决你的问题,请参考以下文章

获取网卡地址

PHP获取MAC地址的函数代码

android 设备如何获取mac地址吗

c/c++/vc/汇编 求助一个可以获得硬件ID号啥的方法啊啊

SnippetsLab for Mac 1.9 中文共享版 – 强大的代码收藏管理工具

php怎样获取客户端电脑物理地址