How to get MAC addresses in C# .NET 2.0

177 Views Asked by At

How can I achieve this:

1. step: I would like to get the Ethernet ("RJ45") MAC Address,

2. step: if there is no existing one, get the WiFi's MAC Address

Important:

  • I'm not interested if the adapter is active or not.
  • also want to exclude WMVare, VPN or other adapters MAC addresses.

Thanks

1

There are 1 best solutions below

5
JonasH On BEST ANSWER

There is the NetworkInterface.GetAllNetworkInterfaces() to list all network adapters. You can then use the NetworkInterfaceType and/or name and description to filter and order adapters. Use .GetPhysicalAddress() to get the MAC address.

If this is for a license system I would suggest listing all valid adapters for whoever grants the license to chose from. A network adapter may be movable between systems, and that may or may not be desirable.