2

I'm using Windows IoT Creators Update on my Raspberry Pi 3 and programming with C#. I want to read my network adapter MAC address.

When I use NetworkInterface.GetAllNetworkInterfaces() it throws NotImplementedException.

Is there another way to get MAC address of my "Ethernet" network?

2

By design, you cannot. Or, at least, you're not supposed to.

But, here's The Thing™.

The Windows 10 IoT Device Portal actually has an address that outputs a JSON version of what you would see on the actual device portal x.x.x.x:8080.

It's http://[IP ADDRESS]:8080/api/networking/ipconfig. In case you need to access it locally (on the device itself, within a Universal App), just replace IP address with localhost.

Sample output (RPi2, latest Windows 10 IoT, Realtek WiFi adapter attached):

{
   "Adapters":[
      {
         "DDNSEnabled":"true",
         "Description":"LAN9512\/LAN9514 USB 2.0 to Ethernet 10\/100 Adapter",
         "HardwareAddress":"b8-27-eb-XX-XX-XX",
         "Index":3,
         "Name":"{4E9618ED-87C2-4426-B587-AACB9A13B4D5}",
         "Type":"Ethernet",
         "DHCP":{
            "LeaseExpires":0,
            "LeaseObtained":0,
            "Address":{
               "IpAddress":"",
               "Mask":""
            }
         },
         "Gateways":[
            {
               "IpAddress":"0.0.0.0",
               "Mask":"255.255.255.255"
            }
         ],
         "IpAddresses":[
            {
               "IpAddress":"0.0.0.0",
               "Mask":"0.0.0.0"
            }
         ]
      },
      {
         "DDNSEnabled":"true",
         "Description":"Realtek RTL8188EU Wireless LAN 802.11n USB 2.0 Network Adapter",
         "HardwareAddress":"00-0b-81-XX-XX-XX",
         "Index":2,
         "Name":"{40734801-CEF4-4896-BD3F-A6E5DF81F298}",
         "Type":"IEEE 802.11",
         "DHCP":{
            "LeaseExpires":1504741254,
            "LeaseObtained":1504741255,
            "Address":{
               "IpAddress":"192.168.249.1",
               "Mask":"255.255.255.255"
            }
         },
         "Gateways":[
            {
               "IpAddress":"192.168.249.1",
               "Mask":"255.255.255.255"
            }
         ],
         "IpAddresses":[
            {
               "IpAddress":"192.168.249.251",
               "Mask":"255.255.255.0"
            }
         ],
         "DNSAddresses":[
            "192.168.40.1",
            "192.168.50.1"
         ]
      },
      {
         "DDNSEnabled":"true",
         "Description":"Microsoft Wi-Fi Direct Virtual Adapter",
         "HardwareAddress":"02-0b-81-XX-XX-XX",
         "Index":4,
         "Name":"{938F3C98-8BEB-434B-8616-C9BEC42E0CA0}",
         "Type":"IEEE 802.11",
         "DHCP":{
            "LeaseExpires":0,
            "LeaseObtained":0,
            "Address":{
               "IpAddress":"",
               "Mask":""
            }
         },
         "Gateways":[
            {
               "IpAddress":"0.0.0.0",
               "Mask":"255.255.255.255"
            }
         ],
         "IpAddresses":[
            {
               "IpAddress":"0.0.0.0",
               "Mask":"0.0.0.0"
            }
         ]
      }
   ]
}

When you connect to that address, you will need to HTTP authenticate like you would when you visit the actual device portal. You will need to use your credentials (Administrator, your-password). In C# code, you would likely use NetworkCredential. I will leave that to you.

After you connect, simply parse the JSON output. Look for HardwareAddress.

  • It is weird that is is "not supposed" to be accessible but the page you are calling must be using the same API that we have access too.. so it must be available to us too.. probably just not documented. +1 for a nice workaround :D – Piotr Kula Sep 18 '17 at 8:23
  • @ppumkin I think the limitation is applicable to UWP apps that are to be distributed to end users. Before one can access the above API, they need the Administrator password, and UWP apps aren't supposed to get admin rights, hence the hack. – PNDA Sep 19 '17 at 5:46
  • @ppumkin Secondly, this API only exists on Windows 10 IoT, but UWP apps are supposed to run on any Windows platform, hence why the lack of documentation. M$ is probably saying "yo, don't implement this solution since it won't work on a PC". – PNDA Sep 19 '17 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.