1. #1
    Platinum Member
    puchu's Avatar
    Join Date
    Mar 2008
    Posts
    816

    Default Automatic incremental ping script

    Once I was looking for a batch script(shell script), that can be used to ping any range of IPs on LAN or internet, but ultimately I thought why not write a script by myself. So here it goes.

    An incremental ping script which will ping a specific range or all the IPs available. This is for IP4 only. For IP6 I will post later once done.


    Create a batch file(same file attached simple-ping-final.zip) with the following code in it and run it.


    @ECHO OFF
    :STR
    ::In the following A,B,C,D are IP values as Ai.Bi.Ci.Di or Ar.Br.Cr.Dr
    ::Range start
    SET Ai=1
    SET Bi=9
    SET Ci=4
    SET Di=5

    ::Range end
    SET Ar=110
    SET Br=197
    SET Cr=40
    SET Dr=155

    :SETIP
    ::IP values concatenated to give an IP address
    SET IP=%Ai%.%Bi%.%Ci%.%Di%

    ::Change the value followed by "-w" in the following ping line to change default ping wait time in case of late or no response
    ::Change the value followed by "-n" in the following ping line to change default number of ping requests to be sent for one IP
    PING -a -n 1 -w 500 %IP%
    IF ERRORLEVEL 1 (echo %IP% Unavailable or not responding) ELSE (echo %IP% Available)
    SET /A Di=%Di%+1
    IF %Di% LSS %Dr% (GOTO SETIP) ELSE (GOTO Ci)

    :Ci
    SET Di=0
    SET /A Ci=%Ci%+1
    IF %Ci% LSS %Cr% (GOTO SETIP) ELSE (GOTO Bi)

    :Bi
    SET Ci=0
    SET Di=0
    SET /A Bi=%Bi%+0
    IF %Bi% LSS %Br% (GOTO SETIP) ELSE (GOTO Ai)

    :Ai
    SET Bi=0
    SET Ci=0
    SET Di=0
    SET /A Ai=%Ai%+0
    IF %Ai% LSS %Ar% (GOTO SETIP) ELSE (GOTO STR)


    ======================
    Results are sometimes unpredictable but least expected to happen.

    If you fail to run the script directly by double-click, then drag the file to command line and hit enter, it should work.

    Everybody is welcome to modify and suggest anything new but do notify about the improvement in this thread.

    I don't think the shell script will have any big difference, so try it by yourself.

    Waiting for comments as always.

  2. #2
    Platinum Member
    puchu's Avatar
    Join Date
    Mar 2008
    Posts
    816

    Default

    Here is the same script with a difference as it allows you to view the output in real time in a web browser, and can be published on a web server.

    I am just an enthusiast and not a coder, so my code may seem untidy.

    You should put the following code in a batch file as mentioned above and place the links for the two HTML files discussed in the script in a third HTML
    file(need to create this file too, code placed after the script below). As these things are variable and any path can be followed to put the HTML files in any folder, it is easier to publish the output on a web-server.

    ################################################## #
    ################################################## #

    Script is as follows:

    echo """""""""""""""""""""""""""""<body bgcolor=black><br><font size=1 face=Tahoma color=white>" > C:\TEMP\PING\ping-Y.htm
    echo """""""""""""""""""""""""""""<body bgcolor=black><br><font size=1 face=Tahoma color=white>" > C:\TEMP\PING\ping-N.htm
    @ECHO OFF
    :STR
    SET Ai=10
    SET Bi=97
    SET Ci=56
    SET Di=50
    SET Ar=10
    SET Br=97
    SET Cr=40
    SET Dr=155
    SET RSTi1=1
    SET RSTi2=1
    SET RSTr1=10
    SET RSTr2=10
    :SETIP
    SET IP=%Ai%.%Bi%.%Ci%.%Di%
    PING -a -n 1 -w 500 %IP% | FIND "TTL="
    IF ERRORLEVEL 1 (SET OUT=4F & SET /A RSTi1=%RSTi1%+1 & echo %IP% Unavailable or not responding & echo %IP% Unavailable or not responding "<br>">> C:\TEMP\PING\ping-N.htm) ELSE (SET OUT=1F & SET /A RSTi2=%RSTi2%+1 & echo %IP% Available "<br>">> C:\TEMP\PING\ping-Y.htm)
    color %OUT%

    :RST1
    IF %RSTi1% LSS %RSTr1% (GOTO RST2) ELSE (SET RSTi1=1 & echo """""""""""""""""""""""""""""<body bgcolor=black><br><font size=1 face=Tahoma color=white>" > C:\TEMP\PING\ping-N.htm)

    :RST2
    IF %RSTi2% LSS %RSTr2% (GOTO NXT) ELSE (SET RSTi2=1 & echo """""""""""""""""""""""""""""<body bgcolor=black><br><font size=1 face=Tahoma color=white>" > C:\TEMP\PING\ping-Y.htm)

    :NXT
    SET /A Di=%Di%+1
    IF %Di% LSS %Dr% (GOTO SETIP) ELSE (GOTO Ci)

    :Ci
    SET Di=0
    SET /A Ci=%Ci%+1
    IF %Ci% LSS %Cr% (GOTO SETIP) ELSE (GOTO Bi)

    :Bi
    SET Ci=0
    SET Di=0
    SET /A Bi=%Bi%+0
    IF %Bi% LSS %Br% (GOTO SETIP) ELSE (GOTO Ai)

    :Ai
    SET Bi=0
    SET Ci=0
    SET Di=0
    SET /A Ai=%Ai%+0
    IF %Ai% LSS %Ar% (GOTO SETIP) ELSE (GOTO STR)

    ################################################## #
    ################################################## #

    The following is a simple frame based HTML page which shows output from the HTML files created by the batch script above with auto-refresh. Change the links in this file to suit your requirement.


    HTML code for the output to be published:



    ################################################## #


    <meta http-equiv=refresh content="1">
    <frameset rows="200,300">
    <frame src="ping-Y.htm">
    <frame src="ping-N.htm">



    ################################################## #
    Inserting HTML code through batch script is not easy otherwise I would have inserted the above HTML code in batch script itself thus limiting the requirement of manual creation, if anybody knows a better way please do share.

    =========
    Going home, will upload both the files at night.

  3. #3
    Platinum Member
    puchu's Avatar
    Join Date
    Mar 2008
    Posts
    816

    Default

    Here are the files for above code.rec-ping.zip

Similar Threads

  1. Replies: 5
    Last Post: 11th May 2012, 07:35 AM
  2. Install a chat script
    By techfreakgag in forum Suggestions and Complaints
    Replies: 14
    Last Post: 5th January 2011, 02:57 PM
  3. Any compression script
    By mickey in forum Broadband How to
    Replies: 2
    Last Post: 16th May 2010, 02:28 AM
  4. Help!script To Download B/w 2-8 A.m.
    By deepak19892009 in forum BSNL broadband
    Replies: 2
    Last Post: 6th April 2008, 10:32 PM
  5. Replies: 9
    Last Post: 10th January 2008, 02:54 AM

Posting Permissions

Log in

Log in
BSNL Broadband Forum Airtel Broadband Forum Reliance Broadband Forum Tikona Broadband Forum MTNL Broadband Forum Tata Broadband Forum
BSNL 3G Forum MTNL 3G Forum Idea 3G Forum Airtel 3G Forum Reliance 3G Forum Vodafone 3G Forum
Airtel Mobile Forum Reliance Mobile Forum BSNL Mobile Forum Idea Mobile Forum Vodafone Mobile Forum Aircel Mobile Forum
Tata Sky Forum Dish TV Forum Reliance DTH Forum Videocon DTH Forum Airtel DTH Forum SUN DTH Forum