Getting Respond Time from Ping Command

1.7k views Asked by At

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

There are 1 answers

0
JosefZ On BEST ANSWER

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.