In Windows/Windows Server, if I have a physical NIC that has two or four ports on it, is there a scriptable/programmatic way to determine which "Network Connection" (such as "Local Area Connection 3", for example,) is associated with which physical NIC port?
I took a quick glance through the win32_networkadapter and win32_networkadapterconfiguration classes, but didn't see anything immediately helpful.
Well, the output of
ipconfig /all
includes the MAC address of all ports on the system.As far as I know, there's no hard and fast way to programmatically correlate these MAC addresses with physical ports. Typically physical interface in cards like these have sequential MAC addresses. In the case of an add-on PCI card, the MAC addresses typically increase numerically starting with the interface closest to the PCI bus.
In the case of built-in ports, I'd just look at the CAM table on the switch it's connected to and then trace cables.
Most high end cards come with a utility that allows you to do advanced configuration tasks. One of the option is commonly to make the lights on the port blink in a set pattern so you can identify the ports.
The big problem is that Windows does not enumerate installed NICs in any particular order. This is a common issue with server configuration. Assuming you're configuring the server manually (which is what we normally do), you can just shut/no shut the ports to see which is connected to what.
If you need your NICs enumerated in a particular order, one trick that I use is to map the ports as described above, then in device manager, delete the NICs that are enumerated incorrectly. When Windows re-installs the NICs they will be randomly assigned again. After doing this a few times while not touching ones that are in the correct order, the enumeration will be correct.
If you need a scriptable NIC enumeration capability, Kelvin Wong has done some work with this using WMI queries to look through the registry. Note that NIC settings in the registry require you to cross-reference multiple entries in different locations, so it will require some work on your part to ensure your script is designed properly.
Here are my finding for HP DL380 servers.
Go to Device Manager -> Network Adapters -> properties of the adapter -> Details, then in Property drop down select "Location information", then in the "Value" box you will see something like "PCL bus 2, device 0, function 0". Here the number for the function can tell you which physical port it is associated wit. Function 0 is for port 1, function 1, is for port 2, function 2 is for port 3, function 3 is for port 4. Hope this helps.
Definitely go to device manager and disable/enable one nic at a time while monitoring what gets disabled/enabled in Network Connections, then you can determine the ports.