如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址? [英] How to get the mac address in WinRT (Windows 8) programmatically?

查看:19
本文介绍了如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WinRT 中寻找 API 来访问 mac 地址.

I am looking for an API in WinRT to access the mac address.

推荐答案

您无法检索 MAC 地址,但您可以检索特定于硬件的信息来识别机器,如果这是您要尝试执行的操作.

You can't retrieve the MAC Address per say, but you do can retrieve hardware specific information to identify a machine if that's what you're trying to do.

这是一篇讨论该主题的完整 msdn 文章:有关使用应用特定硬件 ID (ASHWID) 的指南) 实现每设备应用逻辑 (Windows)

Here's a complete msdn article discussing the subject: Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic (Windows)

请注意仅使用您需要的信息,而不是完整的 ID,因为它可能会根据对您无用的信息(例如 Dock Station 字节)进行更改.

Be careful to use just the information you need and not the complete id, as it might change based on information that are useless to you (such as the Dock Station bytes for instance).

这是一个基于几个字节(CPU id、内存大小、磁盘设备的序列号和bios)计算设备id的代码示例:

Here's a code sample of a computed device id based on a few bytes (CPU id, size of memory, serial number of the disk device and bios):

string deviceSerial = string.Empty;
// http://msdn.microsoft.com/en-us/library/windows/apps/jj553431
Windows.System.Profile.HardwareToken hardwareToken = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
using (DataReader dataReader = DataReader.FromBuffer(hardwareToken.Id))
{
    int offset = 0;
    while (offset < hardwareToken.Id.Length)
    {
        byte[] hardwareEntry = new byte[4];
        dataReader.ReadBytes(hardwareEntry);

        // CPU ID of the processor || Size of the memory || Serial number of the disk device || BIOS
        if ((hardwareEntry[0] == 1 || hardwareEntry[0] == 2 || hardwareEntry[0] == 3 || hardwareEntry[0] == 9) && hardwareEntry[1] == 0)
        {
            if (!string.IsNullOrEmpty(deviceSerial))
            {
                deviceSerial += "|";
            }
            deviceSerial += string.Format("{0}.{1}", hardwareEntry[2], hardwareEntry[3]);
        }
        offset += 4;
    }
}

Debug.WriteLine("deviceSerial=" + deviceSerial);

这篇关于如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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