Getting Respond Time from Ping Command

北城余情 提交于 2019-12-11 03:32:31

问题


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.

If you do a normal ping you get:

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

And I only want:

#time_value

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.

Thanks in advance


回答1:


From command line:

==>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

==>

Used in a batch:

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

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



来源:https://stackoverflow.com/questions/30855909/getting-respond-time-from-ping-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!