- 02-08-11, 06:05 PM #1
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.
- 02-08-11, 06:25 PM #2
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.
- 02-09-11, 03:30 PM #3
Here are the files for above code.rec-ping.zip
Similar Threads
-
High Ping On My City Game Servers And Low Ping On Other Countries Ip Sad Routing
By Shubham Gulati in forum Airtel BroadbandReplies: 5Last Post: 05-11-12, 06:35 AM -
Any compression script
By mickey in forum Broadband How toReplies: 2Last Post: 05-16-10, 01:28 AM -
Some script running in my comp
By aprilsagar in forum Computer SecurityReplies: 2Last Post: 10-01-08, 09:52 PM -
Help!script To Download B/w 2-8 A.m.
By deepak19892009 in forum BSNL broadbandReplies: 2Last Post: 04-06-08, 09:32 PM -
While Ping, Replies are unstable (Modem: Netgear DG632 Ping: 61.0.0.5)
By bodmas in forum BSNL broadbandReplies: 9Last Post: 01-10-08, 01:54 AM
LinkBack URL
About LinkBacks
Reply With Quote