Sunday, October 10, 2010

Get MAC address of your system with c#.Net

This sample code shows how to retrieve the MAC address of your computer using C#.
Can convert this code to VB.NET easily.


public string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}

MACAddress = MACAddress.Replace(":", "");
return MACAddress;
}

1 comment:

  1. Dear Asma

    How are you? I used your technique but it gets me server MAC not Client MAC.

    I know its permission rights but i have seen Sales Force share this informtion . May be they have a certificate active javascript that helps.

    ReplyDelete