vendredi 26 février 2016

Creating a Batch file that pings google constantly and testing the response time

I'm trying to create a batch file that will constantly ping google.com and check the response time - "time=Xms".

  • If the time <= 39ms the text of that ping(or the background) should be green.
  • If the time > 40ms and < 80ms the text of that ping(or the background) should turn orange.
  • If the time >= 80ms the text of that ping(or the background) should turn red.

I have this batch at the moment which pings google every 3 seconds changes the background from green to red if the response fails:

    @echo off
:color 97

:start
PING -n 1 www.google.com 
call :color
goto :start

:color
    IF %ERRORLEVEL% EQU 0 (
        COLOR 27
    ) else (
        COLOR 47
    ping -n 1 127.0.0.1 >nul
    COLOR 74
    ping -n 1 127.0.0.1 >nul
    COLOR 47
    )
    ping -n 3 127.0.0.1 >nul
    GOTO:EOF

This works fine but I don't know how to test response times.

Aucun commentaire:

Enregistrer un commentaire