Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get MAC Address when network adapter is disabled?

Tags:

c#

vb.net

Is there any way i can retrieve MAC Address when Network Adapter is disabled in .net?

Thanks in advance,

like image 993
Ulhas Tuscano Avatar asked Jun 30 '10 05:06

Ulhas Tuscano


1 Answers

It is not possible to get the MAC address of an adapter which is disabled: this is because getting the MAC address requires querying the driver, and the driver for a disabled adapter is not loaded (source).

You can, however get the MAC address of an adapter which is not currently connected.

The WMI route is no good here, because it shows the MAC address as null for adapters which are not connected. The good news is that the NetworkInterface.GetAllNetworkInterfaces() route works just fine:

// using System.Net.NetworkInformation;
var nics = NetworkInterface.GetAllNetworkInterfaces();

// pick your NIC!
var selectedNic = nics.First();

var macAddress = selectedNic.GetPhysicalAddress().ToString();
like image 54
Samuel Jack Avatar answered Oct 21 '22 13:10

Samuel Jack