views:

739

answers:

5

I'm looking for a method to acurately determine if an interface is the physical 802.3 ethernet port on a pc in windows.

Using ipconfig /all I can list all the interfaces, and when I do this on my pc several entries can be listed here including VPN, Bluetooth, Wifi and the physical ethernet interface.

I'm looking for something like, "isPhysical(interface)". (It's ok to have multiple physical lan ports, I just want to know if it is a physical port or not).

UPDATE:

Jay and Chris thanks!

(Not enough space in the comments so I'll post here)

I'm currently looking at using WMI Win32_NetworkAdapter. However, it shows 4 interfaces with AdapterType="Ethernet 802.3".

I only have 1 phyical port on my pc the others have the Name, "Virtual Machine Network Services Driver". (I assume these are installed by my company for some nefarious reason)

I found the attribute I need in the interface, but it's not available in winXP!!!

PhysicalAdapter Data type: boolean Access type: Read-only

Indicates whether the adapter is a physical or a logical adapter. If True, the adapter is physical. Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0: This property is not available.

Is there any way to determine if it's a physical port, other than doing a text filter for the word "Virtual" in the name?

UPDATE 12/08

Looks like the virtual interfaces are added when you have a VM installed.

Here's some details about the virtual adapter: http://blogs.msdn.com/virtual_pc_guy/archive/2005/04/01/404816.aspx

Found an issue where if the user doesn't have admin rights the WMI interface doesn't return the data needed. So, now looking at the GetAdapterInfo method. However, it seems to add 'virtual machine services driver" to the actual adapter's description, making the 'virtual' text check invalid.

And the structure returned by GetAdapterInfo:

http://msdn.microsoft.com/en-us/library/aa366062(VS.85).aspx

A: 

If a machine has two NICs, how will you pick which one is the right one? The only way I've seen this done is giving the user a dropdown combo with each interface's IP address. See Wireshark for an example -

If there are other solutions, I'd like to hear them -

Jeff
It could be multiple ports. Mainly I want a method to determine if the port is the local lan port. somthing like isHardwired(interface).
monkut
A: 

I'm not sure of the answer - but be aware that it is possible to have multiple ethernet interfaces.

RodeoClown
Jeff beat me to it by a few seconds, but what he said...
RodeoClown
+3  A: 

Call GetIfEntry and look for a dwType of IF_TYPE_ETHERNET_CSMACD in the MIB_IFROW structure returned.

Or in .NET, look for a System.Net.NetworkInformation.NetworkInterface with a NetworkInterfaceType of Ethernet.

Jay Hofacker
I haven't tried it but I'm guessing this method would still have the same issue with the virtual adapters listed, right?
monkut
+1  A: 

The best way I've seen so far with any system Windows 2000 SP2 and up is using WMI.

http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx

Win32_NetworkAdapter http://msdn.microsoft.com/en-us/library/aa394216(VS.85).aspx

And you can use the namespace System.Net.NetworkInformation Jay mentioned. Here is a link about detecting what network cards are connected or disconnected:

http://felizk.dk/?p=43

Chris Roland
Thanks, I like the WMI interface for it's ease of access.
monkut
A: 

Check interface via: Call GetIfEntry and look for a dwType of IF_TYPE_ETHERNET_CSMACD in the MIB_IFROW structure returned.

Or in .NET, look for a System.Net.NetworkInformation.NetworkInterface with a NetworkInterfaceType of Ethernet.

And check if the name contains the text, "Virtual".

---This seems like a lame way to check, but so far it's the only method I see to ignore those virtual 802.3 adapters.

monkut