在 WPF 中,可以使用 System.Net.NetworkInformation 命名空间中的 NetworkInterface 类来获取本机的全部 MAC 地址。

以下是一个示例代码,演示如何获取本机的全部 MAC 地址:

using System;
using System.Net.NetworkInformation;

namespace MacAddressExample
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface networkInterface in networkInterfaces)
            {
                PhysicalAddress physicalAddress = networkInterface.GetPhysicalAddress();
                byte[] macBytes = physicalAddress.GetAddressBytes();
                string macAddress = BitConverter.ToString(macBytes);

                Console.WriteLine($"MAC Address: {macAddress}");
            }

            Console.ReadLine();
        }
    }
}

运行该程序,将会输出本机的全部 MAC 地址。

WPF 本机获取全部Mac地址

原文地址: https://www.cveoy.top/t/topic/i9mK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录