sarada

sarada

  • NA
  • 34
  • 0

how to get mac address using C#.net

Jul 20 2009 7:19 AM
hi,
How can i get mac address using C#.net I have used this sample code

  public string GetMACAddress()
        {
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            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;
        }
I am not getting.Can anybody help me

Answers (1)