How to access the MAC address of the system?
I have a code which is working fine but only on localhost. After publishing my website on server, it cannot access the MAC Address and either throw an exception object reference not set to an instance of an object or after using try catch it move to catch block.
I am providing my code, so that anyone can suggest me something fruitful:
public string GetMACAddress()
{
try
{
ManagementClass objMOS = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMOS.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject objMO in objMOC)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
MACAddress = objMO["MacAddress"].ToString();
}
objMO.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
return MACAddress;
}
catch (Exception ei)
{
return "No Mac";
}
}

Ken HPosted Sep 21, 2015, 9:40 PM
Ashutosh TripathiPosted Sep 17, 2015, 10:55 AM
Ken HPosted Sep 1, 2015, 2:05 AM
Ashutosh TripathiPosted Aug 31, 2015, 2:43 PM
Ken HPosted Aug 27, 2015, 9:45 PM
Ashutosh TripathiPosted Aug 27, 2015, 8:48 AM
Ken HPosted Aug 27, 2015, 3:56 AM
Ashutosh TripathiPosted Aug 26, 2015, 3:56 PM
Ken HPosted Aug 25, 2015, 11:26 PM