powershell - 如何在 Windows Bat 或 Powershell 中识别用于成功 ping 的网络适配器(或接口(interface))名称

标签 powershell batch-file networking

有没有办法识别用于成功 ping 的网络适配器(或接口(interface))名称

例如我有以下适配器: Network Adapters

我执行命令

ping google.com

成功了,我想知道使用的适配器是“Wi-Fi”Sunrise_5GHz_387918

c# 也有类似的问题 Identifying active network interface

但我正在寻找一种 Windows 批处理文件方式(可能是 powershell)。

最佳答案

您可以在 PS 中使用以下方法执行此操作:

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

或者, 您可以使用netsh

netsh interface ipv4 show interfaces

在 Windows 8 等较新版本的 PS 中,您甚至可以直接使用:

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

请注意,netconnectionstatus 值指示连接状态。 2表示已连接

关于powershell - 如何在 Windows Bat 或 Powershell 中识别用于成功 ping 的网络适配器(或接口(interface))名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74717902/

相关文章:

google-chrome - 为什么 chrome devtools 网络面板中的大小选项卡有 2 个单元格?

java - 如何从 Windows 执行真正的 Java ping?

unit-testing - 如何发送 RST 而不是正常关闭以进行测试?

powershell - 卸载以特定字符串开头的所有软件

c# - 调用AzureInformationProtection Powershell命令时出现C#Microsoft InformationProtection解密错误

sql-server - 在 SQL Server 上监控什么

javascript - 为什么我从 here-string 中收到 "not a cmdlet"错误?

windows - 如何在批处理文件中执行多个 git 命令而不在第一个命令后终止?

batch-file - 创建批处理文件以轻松刷新网络设置?

powershell - 在 PowerShell 中获取具有 .md5 对应项的所有文件的列表