Ping with a Timestamp

Problem:

I occasionally need to ping a system to check connectivity during off hours. For my results to make sense, I wanted the timestamp for each ping.

Here are a couple of quick ways to do this.

Powershell:

ping.exe -t <_SERVER_>|Foreach{"{0} - {1}" -f (Get-Date),$_}

CMD:

ping -t <_SERVER_>|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!time! !data!)&ping -4 -n 2 %1>nul"

Notes:
  • Change the <_SERVER_> above with the name of the server, or with a %1 if you are running from a batch file
  • If you are running as a batch file, then replace the %a in the CMD example with double percent signs as n %%a.
  • The examples ping forever, if you want to change this change the -t <_SERVER_> with -n 18 <_SERVER_> or something similar.
  • Here is the original post.

 

Leave a Reply