DOS Batch command to ping network IP

Please support our Legacy and Other Languages advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: DOS Batch command to ping network IP

 
0
  #11
May 14th, 2007
I have worked it for you, here are the steps

1) do this once Ping > basefile.txt

This puts results of ping in a file - must be ping that works.

2) then batch file should be

echo off
:start
ping > newfile.txt

fc newfile.txt basefile.txt
if errorlevel 1 goto start
if errorlevel 0 goto nextstep


:nextstep

...... whatever you want to do next when connected
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: DOS Batch command to ping network IP

 
0
  #12
May 30th, 2007
Just a little trick that I picked up from PERL:

|| first or second -----> Do second if first fails

&& first and second --> Do second only if first succeeds

This is a one liner that I came up with to ping a whole subnet. Very quick and dirty so not as nice as it should be:

for /%g in (1,1,254) do @ping 192.168.20.%g 2>&1 > nul && echo Alive 192.168.20.%g || echo Dead 192.168.20.%g

Remember for statements on the command line only use one %G when dereferencing the variable that is iterated. In a batch file or command script, you must use two percent signs, .i.e., %%G.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: DOS Batch command to ping network IP

 
0
  #13
May 31st, 2007
Whoops! I messed up the for statement. It should read:
for /f %g in (1,1,254) do @ping 192.168.20.%g 2>&1 > nul && echo Alive 192.168.20.%g || echo Dead 192.168.20.%g
Sorry. =8(
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: DOS Batch command to ping network IP

 
0
  #14
May 31st, 2007
Originally Posted by mittelgeek View Post
Whoops! I messed up the for statement. It should read:
for /f %g in (1,1,254) do @ping 192.168.20.%g 2>&1 > nul && echo Alive 192.168.20.%g || echo Dead 192.168.20.%g
Sorry. =8(
Hi

Would you explain how this works please, I thought I knew DOS commands quite well.

I have tried this from command prompt on and XP machine and I get 'The system cannot find the file 1.'

Ta

Denis
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,201
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 538
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: DOS Batch command to ping network IP

 
0
  #15
May 31st, 2007
Its a perl script. It needs to be interpreted
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: DOS Batch command to ping network IP

 
0
  #16
Jun 2nd, 2007
Yeah I looked at what I wrote again. FOR /L iterates through a series of numbers using (START,STEP,END) for the parameters.

FOR /F uses the content of (FILENAME or TEXT) as its parameters.

I should have used the /L switch. Try that and it should work.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: DOS Batch command to ping network IP

 
0
  #17
Jun 4th, 2007
I just reread the OP and think that this might do what you need to get done:

@echo off
cls
poweroff wol -ip 192.168.0.3 -subnet 255.255.255.0 -mac 0xxxx00xxxxx

:return
ping 192.168.0.3 > nul || goto wait

cls
exit

:wait
:: Simulates ~60 second wait
:: Credit goes to www.ss64.com/nt/sleep.html

ping -n 61 127.0.0.1 > nul
:: return
goto return
Becareful with GOTOs as they are really bad way to get a loop done. But, eh.

Anyway. I would definitely test this prior to using this in a production machine.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: DOS Batch command to ping network IP

 
0
  #18
Jun 4th, 2007
Originally Posted by mittelgeek View Post
I just reread the OP and think that this might do what you need to get done:

@echo off
cls
poweroff wol -ip 192.168.0.3 -subnet 255.255.255.0 -mac 0xxxx00xxxxx

:return
ping 192.168.0.3 > nul || goto wait

cls
exit

:wait
:: Simulates ~60 second wait
:: Credit goes to www.ss64.com/nt/sleep.html

ping -n 61 127.0.0.1 > nul
:: return
goto return
Becareful with GOTOs as they are really bad way to get a loop done. But, eh.

Anyway. I would definitely test this prior to using this in a production machine.
Thanks, I'll give this a try.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: hwit is an unknown quantity at this point 
Solved Threads: 1
hwit hwit is offline Offline
Newbie Poster

Re: DOS Batch command to ping network IP

 
0
  #19
Jun 4th, 2007
ok hi there i think i figered out how to do it
but it's a litle dificult and i need to look up
some codes but heres the trick:

you make a file of a succesfull ping
wich show howmany paackarived at adres sucesfull there should be 4 if
not mistaken

now u save this in a filed colled "good.txt"

then u u make a batch file with a ping that saves it to a txt file called "ping.txt"
and call this .bat file "ping.bat"

then u make a last and finall .bat called "your desired name here.bat" and let the script
call ping.bat
and compare ping.txt with good.txt
if there the same let it display succes
if it is falls let it display failure

this is yust in short but i'll work out the code and explain it in a tuturial here if u guys would like that
Last edited by hwit; Jun 4th, 2007 at 8:00 pm. Reason: bad gramer needed corections and i wasent clear on one part
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: DOS Batch command to ping network IP

 
0
  #20
Jun 5th, 2007
Originally Posted by hwit View Post
ok hi there i think i figered out how to do it
but it's a litle dificult and i need to look up
some codes but heres the trick:

you make a file of a succesfull ping
wich show howmany paackarived at adres sucesfull there should be 4 if
not mistaken

now u save this in a filed colled "good.txt"

then u u make a batch file with a ping that saves it to a txt file called "ping.txt"
and call this .bat file "ping.bat"

then u make a last and finall .bat called "your desired name here.bat" and let the script
call ping.bat
and compare ping.txt with good.txt
if there the same let it display succes
if it is falls let it display failure

this is yust in short but i'll work out the code and explain it in a tuturial here if u guys would like that

Pardon me - this is exactly what is in my post 22 days ago
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Legacy and Other Languages Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC