Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Using 2 batch files I can ping a network and the client IP addresses...is there any way to modify the batch files below so P1.BAT SET variable can include numbers 1 thru 253; in other words can I create a variable and count 1 --> 253 and pass that value to the second batch file?
Searched all night with no luck and I know there is a simple solution.
P1.BAT
=========
FOR %%I IN (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16) DO CAll c:\p2.bat %%I
P2.BAT
==========
ping -a 192.168.0.%1 >> c:\preslt.txtThanks.

try reading http://gearbox.maem.umr.edu/~batch/intrin1.htm
It has an example where it allows the user to rename files with consecutive numbers. maybe you can adapt it? just try searching at wwww.google.com for: dos batch "count OR counter"
Sorry I can't be exact...it's been 7 years since i even touched a batch file....I used to know it inside and out...now it looks so foreign to me :P (i'm just passing by...I spend my time in the other forums...this is the first time i'm in this forum)

First of all, you don't really need two batch files, you can make that all with only one, like this:
@echo off
if "%1"=="GoTo:" %1%2
FOR %%I IN (1 2 3) DO call %0 GoTo: ping %%I
goto eof
:ping
ping -a 192.168.0.%3 >> c:\preslt.txt
:eofThat's called subroutine.
About the counting, there are many ways to do that. Here's one of them:@echo off
if "%1"=="GoTo:" %1%2
set quit=0
for %%? in (0 1 2 3) do call %0 GoTo: C2 %%?
set quit=
goto eof
:C2
for %%? in (0 1 2 3 4 5 6 7 8 9) do call %0 GoTo: C3 %3%%?
goto eof
:C3
for %%? in (0 1 2 3 4 5 6 7 8 9) do call %0 GoTo: C4 %3%%?
goto eof
:C4
if "%quit%"=="1" goto eof
if "%3"=="253" set quit=1
ping -a 192.168.0.%3 >> c:\preslt.txt:eof
:eofThat will cause the number to have additional zeros (001 002 003...). If you don't want that, use this second one, which won't give any additional zeros (1 2 3...):
@echo off
SET T1=%TEMP%.\TEMP1.BAT
SET T2=%TEMP%.\TEMP2.BAT
SET T3=%TEMP%.\TEMP3.BAT
echo e100'SET %%1='> %T1%
for %%? in (n%T2% rcx 7 w q) do echo %%?>>%T1%
DEBUG nul
type nul>%T1%
:loop
copy/y %T2% %T3% > nul
echo.!>> %T1%
FIND.EXE/c "!" > %T3%
call %T3% IP
ping -a 192.168.0.%IP% >> c:\preslt.txt:eof
if "%IP%"=="253" goto loopend
goto loop
:loopend
for %%? in (%T1% %T2% %T3%) do if exist %%? del %%?
for %%? in (T1 T2 T3) do set %%?=WATCH OUT FOR LINE WRAPPING ON BOTH SCRIPTS!
That's all for Win9x. If you're on NT, it's a lot easier:
FOR /L %%a in (1,1,253) do (
ping -a 192.168.0.%%a >> c:\preslt.txt:eof
)-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br%

SORRY IF THIS MESSAGE IS POSTED TWICE! IF IT IS, CONSIDER THE SECOND ONE
First of all, you don't really need two batch files, you can make that all with only one, like this:
@echo off
if "%1"=="GoTo:" %1%2
FOR %%I IN (1 2 3) DO call %0 GoTo: ping %%I
goto eof
:ping
ping -a 192.168.0.%3 >> c:\preslt.txt
:eofThat's called subroutine.
About the counting, there are many ways to do that. Here's one of them:@echo off
if "%1"=="GoTo:" %1%2
set quit=0
for %%? in (0 1 2 3) do call %0 GoTo: C2 %%?
set quit=
goto eof
:C2
for %%? in (0 1 2 3 4 5 6 7 8 9) do call %0 GoTo: C3 %3%%?
goto eof
:C3
for %%? in (0 1 2 3 4 5 6 7 8 9) do call %0 GoTo: C4 %3%%?
goto eof
:C4
if "%quit%"=="1" goto eof
if "%3"=="253" set quit=1
ping -a 192.168.0.%3 >> c:\preslt.txt:eof
:eofThat will cause the number to have additional zeros (001 002 003...). If you don't want that, use this second one, which won't give any additional zeros (1 2 3...):
@echo off
SET T1=%TEMP%.\TEMP1.BAT
SET T2=%TEMP%.\TEMP2.BAT
SET T3=%TEMP%.\TEMP3.BAT
echo e100'SET %%1='> %T1%
for %%? in (n%T2% rcx 7 w q) do echo %%?>>%T1%
DEBUG < %T1% > nul
type nul>%T1%
:loop
copy/y %T2% %T3% > nul
echo.!>> %T1%
FIND.EXE/c "!" < %T1% >> %T3%
call %T3% IP
ping -a 192.168.0.%IP% >> c:\preslt.txt:eof
if "%IP%"=="253" goto loopend
goto loop
:loopend
for %%? in (%T1% %T2% %T3%) do if exist %%? del %%?
for %%? in (T1 T2 T3) do set %%?=WATCH OUT FOR LINE WRAPPING ON BOTH SCRIPTS!
That's all for Win9x. If you're on NT, it's a lot easier:
FOR /L %%a in (1,1,253) do (
ping -a 192.168.0.%%a >> c:\preslt.txt:eof
)-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Thanks for input.
Great stuff.
One additonal minor issue:
It there a way to only pipe the results if I have successful PING?
Thanks.

![]() |
![]() |
![]() |

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