Logging network connectivity with a Windows batch file

This is a method of periodically logging network connectivity using a simple batch file. The batch file pings google and counts the number of lost responses. The output file, connectivity.log can be analyzed for uptime measurements.

ctest.bat file contents:

ping www.google.com | findstr "Lost" > num_lost_string
FOR /F "tokens=10" %%f IN (num_lost_string) DO  @echo %%f > num_lost
findstr "0" num_lost
IF ERRORLEVEL 1 (
echo|set /p=Down %date% %time%, >> connectivity.log
type num_lost >> connectivity.log
) ELSE (
echo|set /p=Up %date% %time%, >> connectivity.log
type num_lost >> connectivity.log
)
del num_lost_string
del num_lost

Set the batch file to run every few minutes using Windows Task Scheduler UI.

Advertisements