Implementing the getmac.exe functionality

  • Thread starter Thread starter Henrik Dahl
  • Start date Start date
H

Henrik Dahl

Hello!

The getmac.exe program under Windows XP lists the MAC adresses of the
physical network cards. How may I obtain these MAC addresses using .NET?


Best regards,

Henrik Dahl
 
Henrik,

I would use the classes in the System.Management namespace to select all
instances of the Win32_NetworkAddress class. Once you get all instances of
that, you can check the MACAddress property to get the MAC address of the
network adapter. Remember, these are WMI classes, not .NET classes.

Hope this helps.
 
Hello Nicholas,

Yes, I know that, but there's one detail I don't know. I don't want all
instances, only the physical ones and I don't know how to identify whether
the given instance is modelling a physical device. There are plenty of
logical devices. Do you know how to identify the physical devices?


Best regards,

Henrik Dahl

Nicholas Paldino said:
Henrik,

I would use the classes in the System.Management namespace to select all
instances of the Win32_NetworkAddress class. Once you get all instances of
that, you can check the MACAddress property to get the MAC address of the
network adapter. Remember, these are WMI classes, not .NET classes.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Henrik Dahl said:
Hello!

The getmac.exe program under Windows XP lists the MAC adresses of the
physical network cards. How may I obtain these MAC addresses using .NET?


Best regards,

Henrik Dahl
 
Hi Henrik,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to list all the physical
network adapter using WMI. If there is any misunderstanding, please feel
free to let me know.

Here I've written some sample code for you. HTH.

SelectQuery query = new SelectQuery("Win32_NetworkAdapterConfiguration",
"IPEnabled='true'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach(ManagementObject adapterConfig in searcher.Get())
{
Console.WriteLine("\nNewtork Adapter: {0}\nMAC Address: {1}",
adapterConfig["Description"], adapterConfig["MACAddress"]);
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top