【问题标题】:How to get the mac address in WinRT (Windows 8) programmatically?如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?
【发布时间】:2012-11-23 17:22:12
【问题描述】:

我在 WinRT 中寻找一个 API 来访问 mac 地址。

【问题讨论】:

  • 貌似被禁止了,照这个thread,可能是重复的

标签: windows-8 windows-runtime


【解决方案1】:

您无法按说法检索 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);

【讨论】:

    【解决方案2】:

    没有办法做到这一点。 Windows 应用商店应用程序 API 是沙盒的,并且对您可以获得的有关用户的信息非常严格,主要是因为隐私问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 2023-03-27
      • 2011-05-07
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多