static string GetMAC() { StringBuilder sb = new StringBuilder(); NetworkInterface[] networks = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface item in networks) { PhysicalAddress _mac = item.GetPhysicalAddress(); if (_mac.ToString().Length == 12) { foreach (byte i in _mac.GetAddressBytes()) { sb.Append(i.ToString("X2")+"-"); } break; } } return sb.ToString().TrimEnd('-'); } static string GetMACByWMI() { string mac = string.Empty; ManagementClass management = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection m_obj = management.GetInstances(); foreach (ManagementBaseObject item in m_obj) { if (Convert.ToBoolean(item["IPEnabled"]) == true) mac=Convert.ToString( item["MacAddress"]); } return mac.Replace(":","-"); }