当前位置:首页 > 操作系统 > MacOs

C#获取 mac

C#获取 mac

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

<code>        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();

            }
</code>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐