Ping monitor .bat file to check network connection

This simple batch file was used to monitor a network after several complaints about an erratic internet connection. I didn’t want to spend too long on the initial investigation.

Create a file called ping_test.bat and copy the script below.

@echo off

set /p host=Host Address: 
set logfile=log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL 
	TIMEOUT 4
    GOTO Ping)

When you run the script it will prompt for a hostname. The ping time is set to 4 second intervals. Modify the TIMEOUT 4 value to adjust. A log file is created in the same location as the .bat script.

Batch File Ping Test
Batch File Ping Test

Sample output from the log file:

Target Host = google.co.uk 
Pinging google.co.uk [216.58.212.67] with 32 bytes of data: 
05/04/2019 20:38:19 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:24 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:29 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:34 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:39 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:44 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:49 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:54 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:38:59 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:39:04 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:39:09 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52
05/04/2019 20:39:14 Reply from 216.58.212.67: bytes=32 time=19ms TTL=52

 

You May Also Like