之前写过两篇博客,介绍了windows的WMI技术,以及如果通过WMI获取显卡详细信息:
Windows客户端开发–WMI技术介绍
Windows客户端开发–使用WMI获取显卡详细信息(win32控制台程序)

关于获取电脑的mac地址,之前也有相关博客进行了介绍,使用的是QT:
qt中查看本机mac/ip地址

什么是mac地址?
MAC(Media Access Control或者Medium Access Control)地址,意译为媒体访问控制,或称为物理地址、硬件地址,用来定义网络设备的位置。在OSI模型中,第三层网络层负责 IP地址,第二层数据链路层则负责 MAC地址。因此一个主机会有一个MAC地址,而每个网络位置会有一个专属于它的IP地址。

WIKI上是这样描述的:
This article is about the network addressing term. For the series of personal computers by Apple Inc., see Macintosh. For other similar terms, see Mac.

Label of an UMTS router with MAC addresses for LAN and WLAN modules
A media access control address (MAC address) of a computer is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. MAC addresses are used as a network address for most IEEE 802 network technologies, including Ethernet and WiFi. Logically, MAC addresses are used in the media access control protocol sublayer of the OSI reference model.

MAC addresses are most often assigned by the manufacturer of a network interface controller (NIC) and are stored in its hardware, such as the card’s read-only memory or some other firmware mechanism. If assigned by the manufacturer, a MAC address usually encodes the manufacturer’s registered identification number and may be referred to as the burned-in address (BIA). It may also be known as an Ethernet hardware address (EHA), hardware address or physical address (not to be confused with a memory physical address). This can be contrasted to a programmed address, where the host device issues commands to the NIC to use an arbitrary address.

通过WMI获取本机的mac地址:
因为之前已经写过了,所以直接就上代码了:

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
#include <string>#pragma comment(lib, "wbemuuid.lib")int main(int argc, char **argv)
{HRESULT hres;// Initialize COM.hres = CoInitializeEx(0, COINIT_APARTMENTTHREADED);if (FAILED(hres)){cout << "Failed to initialize COM library. "<< "Error code = 0x"<< hex << hres << endl;return 1;              // Program has failed.}// Initialize hres = CoInitializeSecurity(NULL,-1,      // COM negotiates service                  NULL,    // Authentication servicesNULL,    // ReservedRPC_C_AUTHN_LEVEL_DEFAULT,    // authenticationRPC_C_IMP_LEVEL_IMPERSONATE,  // ImpersonationNULL,             // Authentication info EOAC_NONE,        // Additional capabilitiesNULL              // Reserved);if (FAILED(hres)){cout << "Failed to initialize security. "<< "Error code = 0x"<< hex << hres << endl;CoUninitialize();return 1;          // Program has failed.}// Obtain the initial locator to Windows Management// on a particular host computer.IWbemLocator *pLoc = 0;hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator, (LPVOID *)&pLoc);if (FAILED(hres)){cout << "Failed to create IWbemLocator object. "<< "Error code = 0x"<< hex << hres << endl;CoUninitialize();return 1;       // Program has failed.}IWbemServices *pSvc = 0;// Connect to the root\cimv2 namespace with the// current user and obtain pointer pSvc// to make IWbemServices calls.hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), // WMI namespaceNULL,                    // User nameNULL,                    // User password0,                       // LocaleNULL,                    // Security flags                 0,                       // Authority       0,                       // Context object&pSvc                    // IWbemServices proxy);if (FAILED(hres)){cout << "Could not connect. Error code = 0x"<< hex << hres << endl;pLoc->Release();CoUninitialize();return 1;                // Program has failed.}cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;// Set the IWbemServices proxy so that impersonation// of the user (client) occurs.hres = CoSetProxyBlanket(pSvc,                         // the proxy to setRPC_C_AUTHN_WINNT,            // authentication serviceRPC_C_AUTHZ_NONE,             // authorization serviceNULL,                         // Server principal nameRPC_C_AUTHN_LEVEL_CALL,       // authentication levelRPC_C_IMP_LEVEL_IMPERSONATE,  // impersonation levelNULL,                         // client identity EOAC_NONE                     // proxy capabilities     );if (FAILED(hres)){cout << "Could not set proxy blanket. Error code = 0x"<< hex << hres << endl;pSvc->Release();pLoc->Release();CoUninitialize();return 1;               // Program has failed.}// Use the IWbemServices pointer to make requests of WMI. // Make requests here:// For example, query for all the running processesIEnumWbemClassObject* pEnumerator = NULL;hres = pSvc->ExecQuery(bstr_t("WQL"),bstr_t("SELECT * FROM Win32_NetworkAdapter"),WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumerator);if (FAILED(hres)){cout << "Query for processes failed. "<< "Error code = 0x"<< hex << hres << endl;pSvc->Release();pLoc->Release();CoUninitialize();return 1;               // Program has failed.}else{IWbemClassObject *pclsObj;ULONG uReturn = 0;while (pEnumerator){hres = pEnumerator->Next(WBEM_INFINITE, 1,&pclsObj, &uReturn);if (0 == uReturn){break;}VARIANT vtProp;VARIANT vtProp2;// Get the value of the Name propertyhres = pclsObj->Get(L"Description", 0, &vtProp, 0, 0);WCHAR* des;  des = vtProp.bstrVal;hres = pclsObj->Get(L"MACAddress", 0, &vtProp2, 0, 0);WCHAR* mac;mac = vtProp2.bstrVal;if (mac != NULL && des != NULL){wcout << "Description: " << des << endl;wcout << "Description: " << mac << endl;}VariantClear(&vtProp);VariantClear(&vtProp2);}}// Cleanup// ========pSvc->Release();pLoc->Release();CoUninitialize();return 0;
}

输出结果:

Connected to ROOT\CIMV2 WMI namespace
Description: Intel(R) Dual Band Wireless-AC 3160
Description: E4:F8:9C:D9:84:B0Description: VMware Virtual Ethernet Adapter for VMnet1
Description: 00:50:56:C0:00:01Description: VMware Virtual Ethernet Adapter for VMnet8
Description: 00:50:56:C0:00:08Description: Realtek PCIe GBE Family Controller
Description: F0:76:1C:F3:2B:1BDescription: Microsoft Wi-Fi Direct Virtual Adapter
Description: E4:F8:9C:D9:84:B1Description: WAN Miniport (IP)
Description: 80:62:20:52:41:53Description: WAN Miniport (IPv6)
Description: 5E:13:20:52:41:53Description: WAN Miniport (Network Monitor)
Description: 68:EE:20:52:41:53

Windows客户端开发--获取系统mac地址(使用WMI)相关推荐

  1. kotlin获取属性_Kotlin程序获取系统MAC地址

    kotlin获取属性 The task is to get system MAC address. 任务是获取系统MAC地址. package com.includehelp import java. ...

  2. 服务器获取本地mac文件,获取服务器mac地址

    获取服务器mac地址 内容精选 换一换 虚拟IP地址用于为网卡提供第二个IP地址,同时支持与多个弹性云服务器的网卡绑定,从而实现多个弹性云服务器之间的高可用性.该接口用于给云服务器网卡配置虚拟IP地址 ...

  3. 如何用VC++开发读取网卡MAC地址的程序

    如何用VC++开发读取网卡MAC地址的程序 实际的应用系统中,我们往往会需要在程序运行时获取当前机器的网卡的MAC地址,以便作为某种标识之用,如控制程序的合法性等.下文就如何用Microsoft Vi ...

  4. 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    开发语言:C/C++ 支持平台:Windows 实现功能: 通过WMI获取网卡MAC地址.硬盘序列号.主板序列号.CPU ID.BIOS序列号 下载地址: WMI_DeviceQuery.zip 版本 ...

  5. android 获取网卡mac_在安卓6.0(及以上)设备上无法获取无线网卡MAC地址的解决方案...

    在安卓6.0以下的设备上,通过WifiManager.getConnectionInfo().getMacAddress()即可获取WLAN物理地址, 而在6.0及以上,以此方式获取到的MAC地址为固 ...

  6. java如何获得wlan mac_Android M 如何获取 Wifi MAC地址

    今天在撸代码时发现,之前能获取mac地址的方法在nexus 6上返回了"02:00:00:00:00:00",进入设置查看mac地址,结果不相同,肯定有问题,于是就开始上网查资料一 ...

  7. php获取网卡mac地址吗,php获取网卡MAC地址步骤详解

    这次给大家带来php获取网卡MAC地址步骤详解,php获取网卡MAC地址的注意事项有哪些,下面就是实战案例,一起来看一下. php获取网卡的物理地址,即mac地址.<?php /** 获取网卡的 ...

  8. js 获取计算机mac地址,JS获取计算机mac地址以及IP的实现方法

    JS获取计算机mac地址以及IP的实现方法 复制代码 代码如下: //这两个是系统里的ActiveX插件   用来获取ip以及物理地址 if(objObject.IPEnabled   !=   nu ...

  9. C++ 获取物理Mac地址

    C++ 获取物理Mac地址方法: 1. 使用GetAdaptersInfo获取网卡详细信息: 2. 遍历IP_ADAPTER_INFO,取AdapterName去匹配注册表HKEY_LOCAL_MAC ...

最新文章

  1. 关于bcp的那些事儿
  2. Python—实训day7上—Nmupy数值计算基础
  3. spring(10)通过spring 和 JDBC征服数据库
  4. 数组转换为字符串方法
  5. java vo转map_JAVA Map转换为Bean或VO
  6. deleted 表和 inserted 表
  7. 苹果ios15.4RC版发布:新增口罩面容解锁功能
  8. springboot2.1.1连接数据库失败的原因查找
  9. HF-NET环境配置与安装
  10. 身在旋涡中的百度外卖,还能否找到接盘者?
  11. Quickadmin:基于ThinkPhp6+Vue+ElementUI后台管理框架
  12. hibernatexml方式和注解方式实现单实体映射和继承关系映射,eclipse实现
  13. 读《从优秀到卓越》乱摘
  14. 允许用户使用 MAK 密钥激活 Office 2010 批量许可版
  15. 2021-09-19
  16. 微信小程登录功能和获取手机号
  17. 有趣的表情包购物网站
  18. 一文了解百度信息流:百度电商直播、百青藤、观星盘
  19. QAX答题页面js逆向分析(二)
  20. 打印机服务器的系统,打印机服务器主机系统

热门文章

  1. JS按位非(~)运算符与~~运算符的理解
  2. 【定位原理揭秘第三期】室内定位技术原理揭秘
  3. 策略模式(用策略模式实现我们淘宝,京东,美团等等简易满减活动)
  4. mysql多线程复制crash_MySQL 并行复制(MTS) 从库发生异常crash分析
  5. configure error:Package requirements (openssl) were not met
  6. 超级计算机阿波罗11,阿波罗11号制导计算机中指令模块和登月模块原始代码已在 GitHub 上开源...
  7. TCP、UDP、IP头部结构
  8. 华米科技:庇佑之下,黄汪难设温柔乡
  9. 基于51单片机的汽车自动照明灯超声波光敏检测远近光灯方案原理图设计
  10. 按当前位置与其它位置远近排序,按经纬度计算