C# Get the MAC Address of the Host's Physical Network Interface Card

2020年3月21日 3680点热度 1人点赞 0条评论
内容目录

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.

痴者工良

高级程序员劝退师

文章评论