首页 > 代码库 > 获取 Mac 地址 (VC)
获取 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。