Read MAC Address from network adapter in .NET

Jeff picture Jeff · Oct 20, 2008 · Viewed 32.4k times · Source

I'd like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform application

Answer

Stu Mackellar picture Stu Mackellar · Oct 20, 2008

Since .Net 2.0 there's been a NetworkInterface class in the System.Net.NetworkInformation namespace that will give you this information. Try this:

        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (nic.OperationalStatus == OperationalStatus.Up)
            {
                Console.WriteLine(nic.GetPhysicalAddress().ToString());
                break;
            }
        }