Juha Palomäki

Ping with timestamps

Category: Windows

Sometimes it is handy to run ping on the background to monitor network connectivity. Combine Microsoft PowerShell and the PsPing utility from Microsoft and you get a nice logging solution with shows on each line a timestamp and the results from the ping.

Ordinary ping:

psping -t -i 10 server1.example.org \|Foreach{"{0} - {1}" -f (Get-Date),$_} \Tee-object -FilePath ping_log.txt[/code]

TCP port ping:

psping -t -i 10 server1.example.org:80 \|Foreach{"{0} - {1}" -f (Get-Date),$_} \Tee-object -FilePath port_log.txt[/code]

Explanations:

  • -t parameter means run until stopped
  • -i 10 means ping every 10 seconds
  • PowerShell foreach loops through the results add timestamp to each line
  • PowerShell Tee-object is like Unix tee command which both saves the input and sends it to stdout

Credits for the Foreach ping solution: http://stackoverflow.com/a/40591307/350615

Juha Palomäki
Projects
Categories