/// <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; } }