On Windows 7, how to determine network interface being used?

2

How can i get the network interface (route) being used for communication on Windows 7?

On Linux we can get this through:

ip route get 192.168.0.116

And from Windows 8 to 10, using this PS command:

Find-NetRoute -RemoteIPAddress 192.168.0.116 | Select-Object interfaceIndex -Last 1. This gives the index of the network interface being used for communication, and through index we can find the actual network interface.

I have tried tracert, pathping and route PRINT but couldn't get the desired result.

ShahzadIftikhar

Posted 2019-07-10T16:29:24.560

Reputation: 21

post the errors that received from route print, tracert, and pathping. Maybe that Win7 box needs something along the lines of 'netsh ip reset`. – rjt – 2019-07-11T03:06:04.023

Answers

1

This might do it:

$ifIndex = (Get-NetAdapter -physical | where status -eq 'up').ifIndex

harrymc

Posted 2019-07-10T16:29:24.560

Reputation: 306 093

1You can have more than one interface with a status of up, so this might need a bit of tuning. – Doug Deden – 2019-07-10T17:58:20.773

@DougDeden: Usually not physical ones. – harrymc – 2019-07-10T18:03:49.657

Good point. I've got two physical ones up right now, but the second one is the Npcap Loopback Adapter. So that's an edge case -- most people won't have that. – Doug Deden – 2019-07-10T18:30:40.780