protected void Page_Load(object sender, EventArgs e) { ManagementObjectSearcher objQuery = null; ManagementObjectCollection queryCollection = null; try { objQuery = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration"); queryCollection = objQuery.Get(); foreach (ManagementObject mgmtObject in queryCollection) { if (mgmtObject["MacAddress"] != null) { Response.Write(mgmtObject["MacAddress"].ToString()); } } } catch (Exception ex) { Response.Write(ex.Source); Response.Write(ex.Message); } }
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); String sMacAddress = string.Empty; foreach (NetworkInterface adapter in nics) { if (sMacAddress == String.Empty)// only return MAC Address from first card { IPInterfaceProperties properties = adapter.GetIPProperties(); sMacAddress = adapter.GetPhysicalAddress().ToString(); Response.Write(sMacAddress); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)