Computing.Net > Forums > Disk Operating System > Ping several PCs with batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ping several PCs with batch file

Reply to Message Icon

Name: Geoff
Date: June 14, 2002 at 21:29:56 Pacific
Comment:

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.txt

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name:
Date: June 15, 2002 at 01:37:01 Pacific
Reply:

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)


0

Response Number 2
Name: Secret_Doom
Date: June 15, 2002 at 10:47:08 Pacific
Reply:

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
:eof

That'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
:eof

That 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%


0

Response Number 3
Name: Secret_Doom
Date: June 15, 2002 at 10:48:09 Pacific
Reply:

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
:eof

That'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
:eof

That 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


0

Response Number 4
Name: geoff green
Date: June 20, 2002 at 08:25:22 Pacific
Reply:

Thanks for input.

Great stuff.

One additonal minor issue:

It there a way to only pipe the results if I have successful PING?

Thanks.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Ping several PCs with batch file

setup epson with batch file www.computing.net/answers/dos/setup-epson-with-batch-file/5261.html

PC specs batch file ?? www.computing.net/answers/dos/pc-specs-batch-file-/9640.html

How2 simulate keystroke with batch file www.computing.net/answers/dos/how2-simulate-keystroke-with-batch-file/8885.html