954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get MAC Address

how can i get MAC Address in C#?

dehghani
Newbie Poster
1 post since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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
Junior Poster
166 posts since Apr 2005
Reputation Points: 14
Solved Threads: 5
 

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

nicentral
Junior Poster
166 posts since Apr 2005
Reputation Points: 14
Solved Threads: 5
 

System.Net.NetworkInformation.NetworkInterface.GetPhysicalAddress();
or
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); and iterate through each interface, getting the MAC address for each one.

pckujawa
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You