从Ping命令获取响应时间 [英] Getting Respond Time from Ping Command

查看:508
本文介绍了从Ping命令获取响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理文件,该文件将对特定服务器执行ping操作,并且仅显示响应时间.我不在乎值是否存储在变量中.

I'm trying to create a batch file that will ping a certain server and will only display the respond time. I don't mind if value is stored in a variable or not.

如果您执行普通ping操作,您将得到:

If you do a normal ping you get:

Reply from <hostname/server>: bytes=#byte_value time=#time_value TTL=#TTL_value

我只想要:

#time_value

我不知道我是否需要使用特定的tokens或使用findstr作为时间值.到目前为止,我的每一次尝试都失败了.

I don't know if i need to use particular tokens or use findstr for the time value. I have failed every attempts so far.

预先感谢

推荐答案

从命令行:

==>ping -4 -n 1 google.com|findstr /i "TTL="
Reply from 173.194.112.105: bytes=32 time=17ms TTL=56

==>for /F "tokens=7 delims== " %G in ('ping -4 -n 1 google.com^|findstr /i "TTL="') do @echo %G
17ms

==>

批量使用:

for /F "tokens=7 delims== " %%G in ('
    ping -4 -n 1 google.com^|findstr /i "TTL="') do @echo %%G

读取整个for /? FOR /F循环命令:对照另一个命令的结果

Read entire for /? or FOR /F Loop command: against the results of another command.

这篇关于从Ping命令获取响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆