943,542 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
May 14th, 2007
0

Re: DOS Batch command to ping network IP

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
Reputation Points: 22
Solved Threads: 19
Posting Whiz
DenisOxon is offline Offline
345 posts
since Jan 2007
May 30th, 2007
0

Re: DOS Batch command to ping network IP

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005
May 31st, 2007
0

Re: DOS Batch command to ping network IP

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(
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005
May 31st, 2007
0

Re: DOS Batch command to ping network IP

Click to Expand / Collapse  Quote originally posted by mittelgeek ...
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
Reputation Points: 22
Solved Threads: 19
Posting Whiz
DenisOxon is offline Offline
345 posts
since Jan 2007
May 31st, 2007
0

Re: DOS Batch command to ping network IP

Its a perl script. It needs to be interpreted
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,485 posts
since Apr 2005
Jun 2nd, 2007
0

Re: DOS Batch command to ping network IP

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005
Jun 4th, 2007
0

Re: DOS Batch command to ping network IP

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005
Jun 4th, 2007
0

Re: DOS Batch command to ping network IP

Click to Expand / Collapse  Quote originally posted by mittelgeek ...
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.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jun 4th, 2007
0

Re: DOS Batch command to ping network IP

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
hwit is offline Offline
11 posts
since Jun 2007
Jun 5th, 2007
0

Re: DOS Batch command to ping network IP

Click to Expand / Collapse  Quote originally posted by hwit ...
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
Reputation Points: 22
Solved Threads: 19
Posting Whiz
DenisOxon is offline Offline
345 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Legacy and Other Languages Forum Timeline: Euphoria
Next Thread in Legacy and Other Languages Forum Timeline: Lisp question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC