/// <summary> /// 获得当前机器的活动中Mac地址,若无联网则返回空"" /// 需在项目引用中添加 System.Management /// </summary> /// <returns>mac地址,例如:00-00-00-00-00-00</returns> public static string GetNetworkAdpaterID() { try { string mac = ""; ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) if ((bool)mo["IPEnabled"] == true) { mac = mo["MacAddress"].ToString(); break; } moc = null; mc = null; return mac.Trim().Replace(':', '-'); } catch (Exception e) { return "error:" + e.Message; } }
C# 获取正在使用的Mac地址
最新推荐文章于 2024-07-11 10:28:47 发布