I needed to measure how stable my internet connection was, and didn't want to ping every second. So I wrote this batch file to keep track of the ping stats, while waiting longer between each ping. While timeout
is waiting x seconds
, you can press any key (e.g., spacebar) to immediately loop.
@echo off
if "%1"=="" goto help
setlocal ENABLEDELAYEDEXPANSION
set ip=%1
set timeout=%2
set cnt=0
set cntLost=0
set total=0
set min=100000
set max=0
:loop
for /f "tokens=4 delims==" %%i in ('ping -n 1 !ip!^|findstr "100% Average"') do (
set /a cnt+=1
set ms=%%i
set ms=!ms:~0,-2!
set ms=!ms: =!
set loss=!ms:~-4!
if "!loss!" equ "loss" (set lost=1) else (set lost=0)
if !lost! equ 1 (
set /a cntLost+=1
set ms=--
) else (
set /a total+=!ms!
set /a avg=!total!/!cnt!
if !ms! lss !min! set min=!ms!
if !ms! gtr !max! set max=!ms!
)
set /a pLost=!cntLost! * 100 / !cnt!
set msg=time=!ms!ms; Min=!min!ms, Max=!max!ms, Avg=!avg!ms, Total=!cnt!, Lost=!cntLost! ^(!pLost!%%^)
title !msg!
echo Reply from !ip!: !msg!
)
timeout /t !timeout!>nul
goto loop
:help
echo.
echo %0
echo.
echo Usage: %0 ip_address wait_between_pings
echo.
:TheEnd
endlocal
Here is how the output looks.
Reply from x.x.x.x: time=17ms; Min=17ms, Max=17ms, Avg=17ms, Total=1, Lost=0 (0%)
Reply from x.x.x.x: time=15ms; Min=15ms, Max=17ms, Avg=16ms, Total=2, Lost=0 (0%)
Reply from x.x.x.x: time=16ms; Min=15ms, Max=17ms, Avg=16ms, Total=3, Lost=0 (0%)
Reply from x.x.x.x: time=15ms; Min=15ms, Max=17ms, Avg=15ms, Total=4, Lost=0 (0%)
Reply from x.x.x.x: time=10ms; Min=10ms, Max=17ms, Avg=14ms, Total=5, Lost=0 (0%)
Reply from x.x.x.x: time=12ms; Min=10ms, Max=17ms, Avg=14ms, Total=6, Lost=0 (0%)
Reply from x.x.x.x: time=18ms; Min=10ms, Max=18ms, Avg=14ms, Total=7, Lost=0 (0%)
Reply from x.x.x.x: time=12ms; Min=10ms, Max=18ms, Avg=14ms, Total=8, Lost=0 (0%)
Reply from x.x.x.x: time=14ms; Min=10ms, Max=18ms, Avg=14ms, Total=9, Lost=0 (0%)
Now I can see cumulative stats, just like a continuous ping, but still wait a variable number of seconds between each ping.