Networking 可以在.NET Metro应用程序中获取网络MAC地址吗?

Networking 可以在.NET Metro应用程序中获取网络MAC地址吗?,networking,windows-8,microsoft-metro,windows-runtime,Networking,Windows 8,Microsoft Metro,Windows Runtime,我需要在我的Metro UI应用程序中获取网络接口的MAC地址。据我所知,.NET4.5forMetro应用程序API根本不支持这一点。我错了吗 您被限制从Metro风格的应用程序访问低级网络信息,因此这在stock SDK中是不可能的。这是经过设计的。private void getDeviceInfo() private void getDeviceInfos() { Profiles = Windows.Networking.Connectivity.Net

我需要在我的Metro UI应用程序中获取网络接口的MAC地址。据我所知,.NET4.5forMetro应用程序API根本不支持这一点。我错了吗

您被限制从Metro风格的应用程序访问低级网络信息,因此这在stock SDK中是不可能的。这是经过设计的。

private void getDeviceInfo()
    private void getDeviceInfos()
    {
        Profiles = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();
        Adapter = Profiles[0].NetworkAdapter;

        Guid AdapterId = Adapter.NetworkAdapterId;
    }
    IReadOnlyList<Windows.Networking.Connectivity.ConnectionProfile> Profiles;
    Windows.Networking.Connectivity.NetworkAdapter Adapter;
{ Profiles=Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles(); 适配器=配置文件[0]。NetworkAdapter; Guid AdapterId=适配器.NetworkAdapterId; } IReadOnlyList配置文件; Windows.Networking.Connectivity.NetworkAdapter适配器;
您不能检索MAC地址,但可以检索特定于硬件的信息来识别机器

下面是一篇完整的msdn文章,讨论这个主题:

注意只使用您需要的信息,而不是完整的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);
使用(DataReader DataReader=DataReader.FromBuffer(hardwareToken.Id))
{
整数偏移=0;
而(偏移量
Sad face:(.但是我想要MAC地址。这对获取MAC地址有什么帮助?您需要MAC地址的目的是什么?也许有一个替代方案可以解决您的问题。这是一个“OK”持久性计算机标识符。是的,人们可以伪造MAC地址,但同一本地网络中的两个系统很少会有完全相同的MAC地址,这正是我们所需要的。
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);