内容目录
Supports Windows and Linux
var macAddr =
(
from nic in NetworkInterface.GetAllNetworkInterfaces()
where nic.OperationalStatus == OperationalStatus.Up
select nic.GetPhysicalAddress().ToString()
).FirstOrDefault();
Console.WriteLine(macAddr);
There may be multiple network interfaces in the host, such as Ethernet, WLAN, VPN, etc. The method above will obtain the MAC address of the most suitable network interface.
文章评论