Get MAC address of your system


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

Learn Get MAC address of your system


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;
}


Comments

Author: JAYARAJA08 May 2007 Member Level: Gold   Points : 0

gud info thanks for sharing

Author: Raj Kumar Prajapati27 Aug 2008 Member Level: Bronze   Points : 0

IT WORK
THANKS

RAJ PRAJAPAI

Author: Raj Kumar Prajapati27 Aug 2008 Member Level: Bronze   Points : 0

IT WORK
THANKS

RAJ PRAJAPATI

Author: Rajvir Singh Mahala01 Jun 2010 Member Level: Silver   Points : 1

Thanks for this information............

But In which namespace have ManagementClass and ManagementObjectCollection classes.

Thanks

Author: vijetha01 Jun 2010 Member Level: Gold   Points : 1

Add the reference System.Management
and Import System.Management namespace;

Author: senthil kumar02 Jun 2010 Member Level: Gold   Points : 0

very useful thanks

Author: jatin lalcheta26 Jun 2010 Member Level: Gold   Points : 0

hi,
Its very help full.

Thanks...

Regards,
Jatin

Author: Sibtain09 Jun 2011 Member Level: Gold   Points : 1

Thanks for providing this snippet. Its very much helpful for me. I will be using it with some other program logic to generate product key. Your code will provide the core.

Thanks once again.

Guest Author: Tia01 Dec 2011

Hi,
This is not working for me. I have added the namespace : "System.Management;"

Guest Author: Shashank04 Dec 2011

It's awesome.Thanks a lot.

Guest Author: raj12 Feb 2012

the namespace system.management is not avail in vb.net 2003, so i will use this functionality please. help.

Guest Author: KK29 Sep 2014

I need client machine user name, how can i retrieve the client machine name, i have tried for number of scenarios but when hosted to server nothing will works.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: