Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey again,
Im working on a series of batch programs to help me this misc tasks around the network I work at, on feature i would like to include is to be able to ping multiple hosts without user interaction and save the results to a txt file. The only part i am having difficulty with is inputing a range of ip addresses. ie, 10.129.28.0 to 10.129.28.255.
This is part of a script i have already written.
echo.
echo Please specify target. Type 17331 for client PC.
set /p t=Target:
echo.
ping -n 1 -l 1 %t% > nul
if %errorlevel%==0 echo Host %t% is UP! >> %t%.txt
if %errorlevel%==1 echo Host %t% is DOWN! >> %t%.txt
set /p a=Continue? (Y/n):
if "%a%"=="n" exitPlease feel free to post any questions concerning my dilemma and I will answer as soon as possible. Thanks
you would need to have it slowly going upwards, how many Ip's are you using? And what is the range?
You could use somethin like
@echo off
SET t=0
:start
SET /a t=t+1
ping -n 1 -l 1 127.0.0.%t% > nul
if %errorlevel%==0 echo Host %t% is UP! >> 127.0.0.%t%.txt
if %errorlevel%==1 echo Host %t% is DOWN! >> 127.0.0.%t%.txt
IF %t%==999 Exit
Goto start
^^^This would scan from 127.0.0.1-127.0.0.999
You could make it scan any way you want by using increments of increasing variables. So if you wanted to scan every ip addess in this range 0.0.0.0 - 999.999.999.999
@echo off
Set a=0
set b=0
set c=0
set d=0ping -n 1 -l 1 %a%.%b%.%c%.%d% > nul
if %errorlevel%==0 echo Host %a%.%b%.%c%.%d% is UP! >> %a%.%b%.%c%.%d%.txt
if %errorlevel%==1 echo Host %a%.%b%.%c%.%d% is DOWN! >> %a%.%b%.%c%.%d%.txt
:start
SET /a d=d+1IF %d%==1000 (
SET /a c=c+1
set d=0
)
IF %c%==1000 (
SET /a b=b+1
set c=0
)
IF %b%==1000 (
SET /a a=a+1
set b=0
)
IF %a%==1000 EXITping -n 1 -l 1 %a%.%b%.%c%.%D% > nul
if %errorlevel%==0 echo Host %t% is UP! >> %a%.%b%.%c%.%d%.txt
if %errorlevel%==1 echo Host %t% is DOWN! >> %a%.%b%.%c%.%d%.txt
Goto startThis would take about.... a looong time....
Better specify a range :)I only Batch if possible, 2000 more lines of code, oh well.
Report Offensive Follow Up For Removal
thanks for this, i will spend some time implementing it into my script and get back to you. thanks again
Report Offensive Follow Up For Removal
Batchfreak,
Ipv4 addresses only range form, 0.0.0.0 to 255.255.255.255 and if you wanted to ping them all it would be more efficient to use nested for /l loops(in nt+).
@ECHO OFF
for /l %%a in (0,1,255) do (
for /l %%b in (0,1,255) do (
for /l %%c in (0,1,255) do (
for /l %%d in (0,1,255) do (
ping %%a.%%b.%%c.%%d>nul
if errorlevel 1 (echo Host is down.) else echo Host is up.)
)
)
)The actual "work" the script is doing would be faster but the pings would take the same amount of time. The reason for this is the goto jumps cause the command processor to search the batch file for the :label.
Unfortunately using for /l loops to scan ranges is a little more difficult, I may look into it if I have time.
Report Offensive Follow Up For Removal
I agree with Judago. Also, to go through all possible addresses would take 2^32 (about 4 billion) iterations, which would take ages. You probably only need to go through the last one or two loops, depending on your subnet. Also, you probably only want to check from 1 to 254. (255 is used for multicasting for example.)
Report Offensive Follow Up For Removal
A better option would be to use a tool that is designed for this purpose.
Nmap ("Network Mapper") is a free and open source (license) utility for network exploration or security auditing.
This will do a ping sweep of your network and save it in 3 separate formats; normal, xml, and grepable.
nmap -sP -oA filename 10.129.28.0/24
You can also specify a specific range of IP's instead of the CIDR mask.
nmap -sP -oA filename 10.129.28.50-150
-oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
and Grepable format, respectively, to the given filename.
-oA <basename>: Output in the three major formats at once
Report Offensive Follow Up For Removal
thanks for the script Fishmonger. I have been playing around with it and i am still yet to make it in a set range but i am confident that i will. Another question, is it possible to change the interval of each ping, i know it is possible in unix usine ping -i "interval here", can this be done on Windows. I have been unable to find a solution through ping /?
thanks
Report Offensive Follow Up For Removal
just noticed that there are more posts beneath fishmongers. I intend to use the batch for 255-510 address at a time so it shouldnt take to long. I currently use Nmap on both my vista and my unix machines but find it unstable with prolonged session use, besides i prefer to use programs i have written and know that they work and how they work. Important in a security measure.
Report Offensive Follow Up For Removal
Again, finished going over Batchfreak's script and i would have to say that is yhe one best suited for me at this time, fixed just a few errors in your script though, it exports each ping to a different file instead of just the one file and the ip address limit i changed from 999,999.999.999 to 255.255.255.255.
Thanks, I think that this is the script i will implement into my current batch for now.
Report Offensive Follow Up For Removal
Ok, No problem, I haven't worked with ip adress but I knew that it never went over 3 digits. Also, my script was just a demonstration of how it would work, *notices my last sentence*
""This would take about.... a looong time....
Better specify a range :)""I only Batch if possible, 2000 more lines of code, oh well.
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |