C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Videos


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...


Birthday Greetings
Learn Windows 7: How to Fix the COM Surrogate Has Stopped Working Error   Here I would like to share with you a guide on, How to Fix the 'COM Surrogate Has Stopped Working' Error.



Resources » Code Snippets » Network »

Get MAC address of your system


Posted Date: 08 May 2007    Resource Type: Code Snippets    Category: Network
Author: Vinod SharmaMember Level: Silver    
Rating: 1 out of 5Points: 10



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





Responses to the resource: "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


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Check if a port is open or closed?
Previous Resource: How to monitor the network performance using Performance counter?
Return to Resources
Post New Resource
Category: Network


Post resources and earn money!
 
More Resources



About Us    Contact Us    Privacy Policy    Terms Of Use