.netnetwork-programmingmac-address

How to get MAC addresses in C# .NET 2.0


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:

Thanks


Solution

  • 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.