| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 716 人关注过本帖
标题:[求助]VC 中怎么得到PC机的MAC地址啊?
只看楼主 加入收藏
xiaohuawen
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-9-4
收藏
 问题点数:0 回复次数:0 
[求助]VC 中怎么得到PC机的MAC地址啊?

我在网上找了半天,找了一种方法代码如下:但是在编译的时候出错,提示如下:这要怎么解决啊?
--------------------Configuration: cc - Win32 Debug--------------------
Linking...
cc.obj : error LNK2001: unresolved external symbol _Netbios@4
Debug/cc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

cc.exe - 2 error(s), 0 warning(s)


#include <windows.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <iostream>
  #include <string>
  using namespace std;
  #define bzero(thing,sz) memset(thing,0,sz)
  bool GetAdapterInfo(int adapter_num, string &mac_addr)
  {
   // 重启网络适配器以使我们能开始对它查询
   NCB Ncb;
   memset(&Ncb, 0, sizeof(Ncb));
   Ncb.ncb_command = NCBRESET;
   Ncb.ncb_lana_num = adapter_num;
   if (Netbios(&Ncb) != NRC_GOODRET) {
   mac_addr = "bad (NCBRESET): ";
   mac_addr += string(Ncb.ncb_retcode);
   return false;
   }
   // 准备得到适配器状态快
   bzero(&Ncb,sizeof(Ncb);
   Ncb.ncb_command = NCBASTAT;
   Ncb.ncb_lana_num = adapter_num;
   strcpy((char *) Ncb.ncb_callname, "*");
   struct ASTAT
   {
   ADAPTER_STATUS adapt;
   NAME_BUFFER NameBuff[30];
   } Adapter;
   bzero(&Adapter,sizeof(Adapter));
   Ncb.ncb_buffer = (unsigned char *)&Adapter;
   Ncb.ncb_length = sizeof(Adapter);
   // 取适配器信息,如果成功按标准colon-delimited格式返回它
   if (Netbios(&Ncb) == 0)
   {
   char acMAC[18];
   sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
   int (Adapter.adapt.adapter_address[0]),
   int (Adapter.adapt.adapter_address[1]),
   int (Adapter.adapt.adapter_address[2]),
   int (Adapter.adapt.adapter_address[3]),
   int (Adapter.adapt.adapter_address[4]),
   int (Adapter.adapt.adapter_address[5]));
   mac_addr = acMAC;
   return true;
   }
   else
   {
   mac_addr = "bad (NCBASTAT): ";
   mac_addr += string(Ncb.ncb_retcode);
   return false;
   }
  }
  int main()
  {
   // 得到适配器列表
   LANA_ENUM AdapterList;
   NCB Ncb;
   memset(&Ncb, 0, sizeof(NCB));
   Ncb.ncb_command = NCBENUM;
   Ncb.ncb_buffer = (unsigned char *)&AdapterList;
   Ncb.ncb_length = sizeof(AdapterList);
   Netbios(&Ncb);
   // 得到所有的本地以太网地址
   string mac_addr;
   for (int i = 0; i < AdapterList.length - 1; ++i)
   {
   if (GetAdapterInfo(AdapterList.lana[i], mac_addr))
   {
   cout << "Adapter " << int (AdapterList.lana[i]) <<
   "'s MAC is " << mac_addr << endl;
   }
   else
   {
   cerr << "Failed to get MAC address! Do you" << endl;
   cerr << "have the NetBIOS protocol installed?" << endl;
  
  break;
   }
   }
   return 0;
  }

搜索更多相关主题的帖子: MAC PC机 地址 
2006-09-04 10:13
快速回复:[求助]VC 中怎么得到PC机的MAC地址啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025588 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved