Ping – timestamp (batch script)

Sometimes you may need to gather ping statistic from the specific host. If for some reason you cannot use any monitor tool then you can just use ping command and direct the result into a txt file. The problem is that ping command does not output any timestamp so you don’t know when the outage occurs.

Standard ping command

Standard ping command

To solve the issue you can use this simple Windows script (*.bat). In the example below the result is saved into ping.txt file. The script pings the 195.149.238.210 address. I tested it on Windows 7 and Windows 8 machines.

@echo off
set "file=D:\Documents\docs\IT\scripts\ping.txt"
set ip=195.149.238.210

setlocal enabledelayedexpansion
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 -l 1500 -w 7000 ^|findstr "TTL limit timed"  ') do >> "%file%" echo %%a - !date! - !time!&echo %%a 
timeout /t 1 1>nul 2>nul
REM ping 1.1.1.1 -n 1 -w 1000>nul
goto :loop

The content of the output file (ping.txt) is shown below:

Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:48:52,95
Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:48:53,21
Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:48:54,24
Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:48:55,16
Reply from 195.149.238.210: bytes=1500 time=11ms TTL=54 - 2015-08-24 - 20:48:56,19
Reply from 195.149.238.210: bytes=1500 time=11ms TTL=54 - 2015-08-24 - 20:48:57,22
Reply from 195.149.238.210: bytes=1500 time=17ms TTL=54 - 2015-08-24 - 20:48:58,14
Reply from 195.149.238.210: bytes=1500 time=12ms TTL=54 - 2015-08-24 - 20:48:59,18
Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:49:00,21
Reply from 195.149.238.210: bytes=1500 time=10ms TTL=54 - 2015-08-24 - 20:49:01,24
Reply from 195.149.238.210: bytes=1500 time=13ms TTL=54 - 2015-08-24 - 20:49:02,16

Different approach – fping application

You can also download and use improved ping command – see my another post about fping application.

Sources

  1. dostips forum: http://www.dostips.com/(…)

Leave a Reply

Your email address will not be published. Required fields are marked *