C#获取 mac

C#获取 mac

public static String getLocalMacAddress()
{//没有缓存的地址,则查询
String mac_s = “”;

        IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
        if (nics == null || nics.Length < 1)
        {

            return mac_s;
        }

        try
        {

            foreach (NetworkInterface adapter in nics)
            {
                IPInterfaceProperties properties = adapter.GetIPProperties(); //  .GetIPInterfaceProperties();
                string Description = adapter.Description;//接口的描述
                string NetworkInterfaceType = adapter.NetworkInterfaceType.ToString();//获取接口类型
                PhysicalAddress address = adapter.GetPhysicalAddress();//返回MAC地址
                if (NetworkInterfaceType != "Loopback" && NetworkInterfaceType == "Ethernet")

                    mac_s= adapter.GetPhysicalAddress().ToString();

            }
上一篇:短视频平台源码,动态上传的图片以九宫格形式展示


下一篇:Linux I2C内核架构分析,基于三星I2C控制