Resources » Code Snippets » Network

Get MAC address of your system


Posted Date: 08-May-2007  Last Updated:   Category: Network    
Author: Member Level: Silver    Points: 10


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


Did you like this resource? Share it with your friends and show your love!

Responses to "Get MAC address of your system"
Author: JAYARAJA    08 May 2007Member Level: Gold   Points : 0
gud info thanks for sharing


Author: Raj Kumar Prajapati    27 Aug 2008Member Level: Bronze   Points : 0
IT WORK
THANKS

RAJ PRAJAPAI



Author: Raj Kumar Prajapati    27 Aug 2008Member Level: Bronze   Points : 0
IT WORK
THANKS

RAJ PRAJAPATI




Author: Rajvir Singh Mahala    01 Jun 2010Member Level: Silver   Points : 1
Thanks for this information............

But In which namespace have ManagementClass and ManagementObjectCollection classes.

Thanks



Author: vijetha    01 Jun 2010Member Level: Gold   Points : 1
Add the reference System.Management
and Import System.Management namespace;



Author: senthil kumar    02 Jun 2010Member Level: Gold   Points : 0
very useful thanks


Author: jatin lalcheta    26 Jun 2010Member Level: Gold   Points : 0
hi,
Its very help full.

Thanks...

Regards,
Jatin



Author: Sibtain    09 Jun 2011Member 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: Tia     01 Dec 2011
Hi,
This is not working for me. I have added the namespace : "System.Management;"



Guest Author: Shashank     04 Dec 2011
It's awesome.Thanks a lot.


Guest Author: raj     12 Feb 2012
the namespace system.management is not avail in vb.net 2003, so i will use this functionality please. help.


Guest Author: KK     29 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.


Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Program
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India