943,603 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 91085
  • C# RSS
Apr 26th, 2005
-1

Get MAC Address

Expand Post »
how can i get MAC Address in C#?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dehghani is offline Offline
1 posts
since Apr 2005
Apr 27th, 2005
0

Re: Get MAC Address

Use the Management Class object in .NET.

C# Syntax (Toggle Plain Text)
  1. ManagementClass oMClass = new ManagementClass ("Win32_NetworkAdapterConfiguration");
  2.  
  3. ManagementObjectCollection colMObj = oMCLass.GetInstances();
  4.  
  5. foreach(ManagementObject objMO in colMObj)
  6. {
  7. Console.WriteLine(objMO["MacAddress"].ToString());
  8. }
Makes sense?

Andy
Last edited by Nick Evan; Jan 7th, 2010 at 4:40 am.
Reputation Points: 14
Solved Threads: 5
Junior Poster
nicentral is offline Offline
166 posts
since Apr 2005
Jan 21st, 2008
0

Re: Get MAC Address

Click to Expand / Collapse  Quote originally posted by nicentral ...
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
Reputation Points: 14
Solved Threads: 5
Junior Poster
nicentral is offline Offline
166 posts
since Apr 2005
Jan 6th, 2010
0
Re: Get MAC Address
System.Net.NetworkInformation.NetworkInterface.GetPhysicalAddress();
or
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); and iterate through each interface, getting the MAC address for each one.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pckujawa is offline Offline
1 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: catch C++ DLL exception
Next Thread in C# Forum Timeline: C# installed application visibility





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC