C#

Get machine’s MAC address using C#

Let’s see some C# code that gets the MAC Address of the network interface controller that is up.

1
2
3
4
5
6
7
8
9
String mac = "";
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
	if (ni.OperationalStatus == OperationalStatus.Up)
	{
		mac = ni.GetPhysicalAddress().ToString();
		break;
	}
}