I asked yesterday about changing the color in command prompt based on a ping result. A user was kind enough to supply me with the script below.
The script works great except for one problem. When the connection times out, it does nothing. It just sort of pauses. How would I update this script to include a variable or something that will also change the text if a time out is reported?
@setlocal enableextensions enabledelayedexpansion
@echo off
set /p ipaddr="Enter ip or url: eg localhost or google.co.za or 192.168.0.1"
set /p cutoff="enter minimum good reply ms: eg 300 "
:loop
for /f "tokens=7,9" %%a in ('ping -n 1 !ipaddr!') do (
if "%%a"=="Average" (
set a=%%b
set /a res=!a:~0,-2!
)
)
if %res% LEQ %cutoff% (
COLOR 2
echo %ipaddr% responded in %res%ms
)else (
COLOR 4
echo %ipaddr% responded in %res%ms
)
ping -n 3 127.0.0.1 >nul: 2>nul:
goto :loop
endlocal