实现这个功能,我们可以借助微软的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);
- }
复制代码
上位机MFC如何获得本地计算机的MAC地址
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|