如何获得Mac地址 [英] How to get onboard Mac Address

查看:73
本文介绍了如何获得Mac地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要系统的Mac地址。我为它编写代码,但它提供了多个Mac地址,例如它给Lancard mac地址,USB加密狗macaddress,板载Mac地址等等,但我的要求是只使用MFC获得板载Mac地址。

In my project i need Mac Address of system. i write code for it but it gives multiple Mac Address for exemple it give Lancard mac adress, USB dongle macaddress , On-Board Mac address etc. but my reqirement is to get only On-Board Mac Address using MFC.

推荐答案

除了几个例外,MAC地址通常不会连接到主板。它对于网络适配器是唯一的(如果有多个适配器,则每个适配器一个)。有几种方法可以获得此信息。这是一个:



With several exceptions, the MAC address is not usually associated connected to the motherboard. It is unique to the network adapter (one per adapter if there are more than one). There are several ways to do get this info. Here is one:

#include <stdio.h>
#include <WinSock.h>
#pragma comment(lib, "wsock32.lib")

int main(int argc, char *argv[])
{
 WORD wVersionRequested;
 WSADATA wsaData;
 char name[255];
 PHOSTENT hostinfo;
 wVersionRequested = MAKEWORD( 1, 1 );
 char *ip;

 if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
  if( gethostname ( name, sizeof(name)) == 0)
  {
   printf("Host name: %s\n", name);

   if((hostinfo = gethostbyname(name)) != NULL)
   {
    int nCount = 0;
    while(hostinfo->h_addr_list[nCount])
    {
     ip = inet_ntoa(*(
          struct in_addr *)hostinfo->h_addr_list[nCount]);

     printf("IP #%d: %s\n", ++nCount, ip);
    }
   }
  }
 return 0;
}





另外,在其中 [ ^ ]是一篇关于如何以3种不同的方式获得它。在获得多个答案的情况下,您需要以自己的方式确定所需的方法。



Also, here[^]is an article on how to get it 3 different ways. You need to come up with your own way to determine the one you want in the case that you get multiple answers.


我们不知道您的代码在做什么,但是您检查了< a href =http://msdn.microsoft.com/en-us/library/aa394582.aspx> WMI的文档 [ ^ ]?
We have no idea what your code is doing, but have you checked the documentation for WMI[^]?


这篇关于如何获得Mac地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆