RSS Forums RSS

Get MAC Address

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Reply
Posts: 1
Reputation: dehghani is an unknown quantity at this point 
Solved Threads: 0
dehghani dehghani is offline Offline
Newbie Poster

Get MAC Address

  #1  
Apr 26th, 2005
how can i get MAC Address in C#?
AddThis Social Bookmark Button
Reply With Quote  
Posts: 156
Reputation: nicentral is an unknown quantity at this point 
Solved Threads: 4
nicentral's Avatar
nicentral nicentral is offline Offline
Junior Poster

Re: Get MAC Address

  #2  
Apr 27th, 2005
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
Nobody believes the official spokesman, but everybody trusts an unidentified source.

-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
Reply With Quote  
Posts: 156
Reputation: nicentral is an unknown quantity at this point 
Solved Threads: 4
nicentral's Avatar
nicentral nicentral is offline Offline
Junior Poster

Re: Get MAC Address

  #3  
Jan 21st, 2008
Originally Posted by nicentral View Post
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
Nobody believes the official spokesman, but everybody trusts an unidentified source.

-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 47807 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:23 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC