How to Get MAC address programatically in c# for a windows mobile 6.0 device

后端 未结 2 583
醉话见心
醉话见心 2021-01-05 08:56

How to Get MAC address programatically in c# for a windows mobile 6.0 device? The System.Net.NetworkInformation is not supported in ,net compatc framework 3.5.

2条回答
  •  半阙折子戏
    2021-01-05 09:20

    I know it's been awhile, but I needed this and found I could use OpenNETCF version of the code above with a tweak:

    INetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    //for each j you can get the MAC 
    PhysicalAddress address = nics[0].GetPhysicalAddress();
    byte[] bytes = address.GetAddressBytes();
    for(int i = 0; i < bytes.Length; i++) {
        // Display the physical address in hexadecimal. 
        Console.Write("{0}", bytes[i].ToString("X2"));
        // Insert a hyphen after each byte, unless we are at the end of the address. 
        if(i != bytes.Length - 1) {
            Console.Write("-");
        }
    }
    

提交回复
热议问题