0

众所周知,ping 任何 IP 的结果由两部分组成。第一部分是来自 .... 的回复,它只是一行,第二部分是多行属于统计信息。我想要两个删除第二部分。我只需要第一行输出而不是统计信息。有什么命令可以做到这一点吗?

4

3 回答 3

0
set "line="
for /f "delims=" %%a in ('ping 127.0.0.1 -n 1') do if not defined line set "line=%%~a"
echo %line%
于 2013-09-09T15:50:58.337 回答
0

这是一个替代方案。

ping www.google.com -n 1 |find /i "reply from" >> file.log

您可能只需要它提供的信息:

ping www.google.com -n 1 |find /i "TTL" >> file.log
于 2013-09-09T22:19:53.113 回答
0

这是一个旧线程,但谷歌把我带到了这里,所以如果它对其他人有用,这可能会有所帮助:

无论 ping 响应还是失败,这里都会给出一条回复:

ping -n 1 127.0.0.1 | find "y "

你会得到:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

- 或者 -

Ping request could not find host 127.0.0.1. Please check the name and try again.

“-n 1”将 ping 过程限制为仅 1 个 ping,并且使用查找“y”,因为字母“y”和空格对两个响应都是通用的 - 在“Reply”和“try”这两个词中。

于 2017-06-23T06:57:32.020 回答