windows-8 - 如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?

标签 windows-8 windows-runtime

我正在寻找 WinRT 中的 API 来访问 mac 地址。

最佳答案

你不能说每个人都检索 MAC 地址,但如果这是你想要做的,你可以检索硬件特定信息来识别机器。

这是讨论该主题的完整 msdn 文章:Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic (Windows)

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

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

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);

关于windows-8 - 如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12892189/

相关文章:

c# - 如何从可移植类库中调用 REST 服务?

dependency-injection - 适用于 Windows 8 Metro 应用程序的依赖注入(inject)框架

windows-8 - 如何为 Windows 8 应用程序提供 3 种初始屏幕尺寸?

c# - 调试异步代码时如何关闭蓝色时钟显示?

.net - 使用Windows Runtime异步文件API来确保顺序文件访问?

有关未定义或 null 引用的 JavaScript 运行时错误

c# - 通过 HttpClient.PostAsync 的 POST 请求,主体内有 StorageFile (WinRT)

windows-8 - 在 WinRT 中流式传输到文件

xaml - 如何让组合框只在 Windows 8 中向下拉伸(stretch)

windows-8 - 离线下载windows phone sdk 8