Bat file for continuous Ping with background Colour changes

September 8th, 2010 | 10 Comments | Posted in Programming

We are using ping command to monitor the networks, Sometimes we have to monitor multiple IP address with continuous ping in different windows. Normal command line is with a black colour background and white text. But it will be better to show a red window if the Request timed out. And the default success pings with a green background. Here is the script to do the ping with color output results.

What is happening in this Batch file?

Prompting an IP address and set to a variable named %IP%, and its pinging once with 32 bytes of data.  If it is failed the background color will change to red. And display “Request timed out” then wait for some title . We used a self ping for sleep function. The code put it in loop so it will ping continuously.

:: Batch Script
:: color Ping
:: Code By Binbert.com
echo off & cls
set /p IP=Enter your IP Address :
:top
PING  -n 1 %IP% | FIND "TTL="
IF ERRORLEVEL 1 (SET OUT=4F  & echo Request timed out.) ELSE (SET OUT=2F)
color %OUT%
ping -n 2 -l 10 127.0.0.1 >nul
GoTo top
Leave a Reply 15045 views, 13 today |
Tags: , ,

Author :

I am a Technology Blogger, I Blog about technology related articles, Active in online and offline tech communities
Follow Discussion

10 Responses to “Bat file for continuous Ping with background Colour changes”

  1. Jain Scaria Says:

    Dear Albin,
     
    Really it is useful for monitoring purpose and reduce the stress of  monitoring person. I checked it is working  fine
     
    Regards,
    Jain Scaria

  2. Mohan Sen Says:

    @Albin

    Really it is a good effort; ease of use and makes monitoring effortless

  3. Mohan Sen Says:

    @albin

    I forget to comment one more thing , while we giving the batch file name as ping.bat, it is not responding, otherwise no problem

    Useful one

  4. Albin Sebastian Says:

    @mohan

    Thanks for your command,

     

    Dear readers …

    Please don’t use ping.bat as the file name. because there is a “ping” command already working inside the batch file

  5. Harish Says:

    nice one……….:)

  6. Alis Says:

    How to use this color function in Ping -t  ?

  7. Albin Sebastian Says:

    Color is a dos command to change the cmd colors. Here we changing colors Red and green according to ping error level

  8. Avinash Says:

    hi i want to ping multiple IP for ex ping -n 4 10.1.2.12
    ping -n 4 10.1.2.13
    ping -n 4 10.1.2.14
    ping -n 4 10.1.2.21
    ping -n 4 10.1.2.22
    ping -n 4 10.1.2.23
    ping -n 4 10.1.2.24
    ping -n 4 10.1.2.25
    ping -n 4 10.1.2.26
    ping -n 4 10.1.2.27
    ping -n 4 10.1.2.28
    ping -n 4 10.1.2.31

    ten what how it will work.. please help

  9. Albin Sebastian Says:

    @Avinash

    Ping will happen only on a singl IP address. You can write a script to ping one by one..

    Replace %IP% with the IP addressees which you want to ping.

    you can remove “ping -n 2 -l 10 127.0.0.1 >nul” from the script, It is just for a sleep function

     

  10. Luz Toto Says:

    how are you, primary blog on fatlike loss. such a person helped.

Leave a Reply

You must be logged in to post a comment.


More in Programming (2 of 9 articles)