Read MAC Address from network adapter in .NET

前端 未结 7 1941
梦谈多话
梦谈多话 2020-11-29 07:02

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

7条回答
  •  遥遥无期
    2020-11-29 07:26

    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;
                }
            }
    

提交回复
热议问题