2

Is there a way to identify the network adapter (or interface) name used for a successful ping

eg I have the following adapters: Network Adapters

I perform the command

ping google.com

which is successful, I would like to know that the adapter used is either "Wi-Fi" Sunrise_5GHz_387918

There is a similar question for c# Identifying active network interface

But I am looking for a windows batch file way (possibly powershell).

shelbypereira
  • 2,097
  • 3
  • 27
  • 50
  • One possibility is to use WMIC, if it is installed on your computer: `%__APPDIR__%wbem\WMIC.exe /NameSpace:\\root\StandardCimv2 path MSFT_NetAdapter where "InterfaceOperationalStatus='1' and Virtual='FALSE'" get name` – Qwerty Dec 07 '22 at 14:24
  • Just be aware, there can be more than one connected network device at any one time. This means that it is possible that you may incorrectly identify the wrong one, because the above comment code, and all of those in the accepted answer can each output multiple results. – Compo Dec 07 '22 at 15:10

1 Answers1

2

You can do that in PS using:

get-wmiobject win32_networkadapter | select netconnectionid, name, InterfaceIndex, netconnectionstatus

OR, You can use netsh

netsh interface ipv4 show interfaces

In the newer version of PS like in windows 8, you can even directly use:

Get-NetAdapter | SELECT name, status, speed, fullduplex | where status -eq 'up'

Note by that the netconnectionstatus value indicates the connection status. 2 indicates connected

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45