Networking – How to tell which of multiple network cards is in use

netstatnetwork-adapternetworkingping

Suppose I have multiple network cards connected to my PC, how can I know which card is used for communication. For example, if I use

ping 192.168.x.xxx

I would like to know which card (and which IP address) used for communication.

The command

netstat

will tell us about the active connections. I am not interested in active connections, but I would like to know which card will be used for next connection. That is, if we use ping which card (or IP address) will be used ?

Best Answer

Try route print; it'll show you the OS's table of networks and which network interface it'll use for each, or where there's multiple cards on the one network the weighting it'll use in distributing the traffic. I've only got one card in this machine so this isn't very interesting:

===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 12 34 56 78 9a ...... Intel(R) 82566DM Gigabit Network Connection
===========================================================================
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      123.45.67.1   123.45.67.137       10
        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1
      234.254.0.0      255.255.0.0    123.45.67.137   123.45.67.137       20
      123.45.67.0    255.255.255.0    123.45.67.137   123.45.67.137       10
    123.45.67.137  255.255.255.255        127.0.0.1       127.0.0.1       10
   123.45.255.255  255.255.255.255    123.45.67.137   123.45.67.137       10
        224.0.0.0        240.0.0.0    123.45.67.137   123.45.67.137       10
  255.255.255.255  255.255.255.255    123.45.67.137   123.45.67.137       1
    Default Gateway:       123.45.67.1
===========================================================================
Persistent Routes:
  None

so e.g. from the second line traffic to 127.x.x.x will use the loopback interface but traffic to multicast and everything else will use the network card. I'm not sure how to read this programattically, though, sorry.

Related Question