Problem with retrieving of MacAddress ?!?!?!

T

Toma Marinov

Hello !
First, excuse me for my not very good english! >:O(
With this code below, I retrieve the MAC address of my
network card from WMI class Win32_NetworkAdapter, and add
it to ListBox :

String strSQL;
ObjectQuery objQry = null;
ManagementObjectSearcher objSearcher = null;

strSQL = "SELECT * FROM Win32_NetworkAdapter ";
objQry = new ObjectQuery (strSQL);
objSearcher = new ManagementObjectSearcher (objQry);
this.lbMac .Items.Clear ();
foreach (ManagementObject objM in objSearcher.Get ())
{
if (objM["MACAddress"] != null)
{
this.lbMac.Items.Add (objM["MACAddress"].ToString());
}

}//FOR

This work, but the problem is that the result is six MAC
addresses, but I have only one network card. And only the
first address is the address if my network card.
Can someone tell me - from where the rest 5 MAC addresses
appear ?

Thank you !
Toma Marinov
 
W

Willy Denoyette [MVP]

"Select * FROM Win32_NetworkAdapter " returns all network adapter
instances, that is LAN adapters (wired and wireless), serial ports (WAN
adapters used by RAS), infrared port(s) Firewire adapters etc.

So you need to refine your query if you only need one specific adapters MAC
address.

Willy.
 
W

Wiktor Zychla

strSQL = "SELECT * FROM Win32_NetworkAdapter ";

you have to somehow restrict the resultset to get only the active network
adapter. start with:

strSQL = "SELECT * FROM Win32_NetworkAdapter WHERE IPEnabled = 'TRUE'";

Wiktor Zychla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top