DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Get MAC Address (http://www.daniweb.com/forums/thread22577.html)

dehghani Apr 26th, 2005 9:15 am
Get MAC Address
 
how can i get MAC Address in C#?

nicentral Apr 27th, 2005 1:25 pm
Re: Get MAC Address
 
Use the Management Class object in .NET.

ManagementClass oMClass = new ManagementClass ("Win32_NetworkAdapterConfiguration");

ManagementObjectCollection colMObj = oMCLass.GetInstances();

foreach(ManagementObject objMO in colMObj)
{
Console.WriteLine(objMO["MacAddress"].ToString());
}

Makes sense?

Andy

nicentral Jan 21st, 2008 12:29 pm
Re: Get MAC Address
 
Quote:

Originally Posted by nicentral (Post 115961)
Use the Management Class object in .NET.

ManagementClass oMClass = new ManagementClass ("Win32_NetworkAdapterConfiguration");

ManagementObjectCollection colMObj = oMCLass.GetInstances();

foreach(ManagementObject objMO in colMObj)
{
Console.WriteLine(objMO["MacAddress"].ToString());
}

Makes sense?

Andy

You might want to also add

Console.WriteLine(objMO["Caption"].ToString());

to your test before the mac address so that you know which devices you are looking at.

Also, don't forget to use try/catch blocks on these as a NullPointerReference will kill the app.

Andy


All times are GMT -4. The time now is 5:25 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC