如何在Windows上只获取ping测试的回复行

mas*_*ind 9 windows cmd ping

通常,在ping服务器IP地址时,我们会将此作为回报:

Pinging <IP address> with 32 bytes of data:
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121

Ping statistics for <IP address>:
packets: sent = 4, Received = 4, lost = 0 (0% loss),
Approximate round trip times in milli-secounds:
Minimum = 151ms, Maximum = 151 ms, Average = 151 ms
Run Code Online (Sandbox Code Playgroud)

如何通过Windows上的cmd.exe中的简单命令(无论使用何种Windows语言)获得以下行(仅一个ping测试的回复行)?

Reply from <IP address> : bytes=32 time=151 TTL=121
Run Code Online (Sandbox Code Playgroud)

也许最简单的方法是只显示第二行?该怎么做?因为我不知道如何在Windows上执行此操作.

fox*_*ive 19

这可能更普遍.

ping -n 1 <hostname/IP> | FIND "TTL="
Run Code Online (Sandbox Code Playgroud)


Ofi*_*zon 5

您可以将 findstr 命令与 for 的跳过行选项结合起来:

C:\>ping 127.0.0.1 | for /f "skip=3 tokens=*" %a in ('findstr Reply') do @echo %a
Run Code Online (Sandbox Code Playgroud)

输出是:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Run Code Online (Sandbox Code Playgroud)

如果写入批处理文件%a则更改为。%%a


mjg*_*py3 3

出色地,

ping -n 1 <hostname/IP>
Run Code Online (Sandbox Code Playgroud)

将仅发送 1 个 ping 请求。您应该能够使用该FIND命令找到回复行。

所以,像这样:

ping -n 1 <hostname/IP> | FIND "Reply"
Run Code Online (Sandbox Code Playgroud)

更新

我知道上面的内容可以在英文版 Windows 7 机器上运行。我假设它适用于其他本地化版本,但这可能是一个错误的假设。

更新2

这个问题似乎提供了一些见解。您可能必须将 ping 的输出写入文件(使用>输出重定向管道),然后使用答案中的命令仅获取第二行。