工控编程吧
标题: 上位机MFC如何获得本地计算机的MAC地址 [打印本页]
作者: qq263946146 时间: 2019-8-8 10:15
标题: 上位机MFC如何获得本地计算机的MAC地址
实现这个功能,我们可以借助微软的IPHLPAPI库可以添加按钮点击函数来调用下面代码查看效果
- #include <Nb30.h>
- #pragma comment(lib,"IPHLPAPI.LIB")
- #pragma comment(lib,"netapi32.lib ")
- void CGkbc8Dlg::OnButton2()
- {
- LANA_ENUM num;
- ADAPTER_STATUS status;
- NCB ncb;
- //发送NCBENUM命令,获得网卡的数量和每个网卡的编号
- ncb.ncb_command = NCBENUM;
- ncb.ncb_buffer = (UCHAR*)#
- ncb.ncb_length = sizeof(LANA_ENUM);
- Netbios(&ncb);
- CString strText =_T("本地计算机的MAC地址:\n");
- for (int n = 0; n < num.length; n++)
- {
- //发送NCBRESET命令
- memset(&ncb, 0, sizeof(NCB));
- ncb.ncb_command = NCBRESET;
- ncb.ncb_lana_num = num.lana[n];
- Netbios(&ncb);
- //发送NCBASTAT命令,获得每个网卡的状态
- memset(&ncb, 0, sizeof(NCB));
- ncb.ncb_command = NCBASTAT;
- ncb.ncb_lana_num = num.lana[n];
- memset(ncb.ncb_callname, '*', 1);
- ncb.ncb_buffer = (UCHAR*)&status;
- ncb.ncb_length = sizeof(ADAPTER_STATUS);
- Netbios(&ncb);
- //获得每个网卡的MAC地址
- CString strTemp = _T("");
- strTemp.Format("%02X-%02X-%02X-%02X-%02X-%02X\n",
- status.adapter_address[0],
- status.adapter_address[1],
- status.adapter_address[2],
- status.adapter_address[3],
- status.adapter_address[4],
- status.adapter_address[5]);
- strText += strTemp;
- }
- AfxMessageBox(strText);
- }
复制代码
(, 下载次数: 0)