C# 获取主机的物理网卡的MAC

2020年3月21日 2740点热度 1人点赞 0条评论
内容纲要

支持 Windows 和 Linux

            var macAddr =
                (
                from nic in NetworkInterface.GetAllNetworkInterfaces()
                where nic.OperationalStatus == OperationalStatus.Up
                select nic.GetPhysicalAddress().ToString()
                ).FirstOrDefault();

            Console.WriteLine(macAddr);

主机中可能会存在多个网卡,以太网,WLAN,VPN等,上面的方法会获取最符合条件的网卡的 MAC。

痴者工良

高级程序员劝退师

文章评论