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.

  • 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 Jul 11 '19 at 3:06
1

This might do it:

$ifIndex = (Get-NetAdapter -physical | where status -eq 'up').ifIndex
| improve this answer | |
  • 1
    You can have more than one interface with a status of up, so this might need a bit of tuning. – Doug Deden Jul 10 '19 at 17:58
  • @DougDeden: Usually not physical ones. – harrymc Jul 10 '19 at 18:03
  • 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 Jul 10 '19 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.