Computer Hope

Microsoft => Microsoft DOS => Topic started by: SooPa_fLy on November 01, 2006, 03:46:02 AM

Title: Batch to run ping loop
Post by: SooPa_fLy on November 01, 2006, 03:46:02 AM
Hey guys,

Well I have searched high and low and tried everything but cannot get batch file to ping in a constant loop.
Basically I want to ping an ip constantly to keep a connection going (no not ping flood any1 :P)
Here is what I have so far....

pause
@echo off

for /f "tokens=*" %%I in (C:\DocumentsandSettings\Matt\MyDocuments\Matt\iplist.txt) do call :pinger %%I
goto :eof

:pinger

echo %TIME% >> pingLOG
ping %1 >> pingLOG
:: DONE



Please have a look and advise me where I may have gone wrong or what I can do to make this work.
It would be greatly appreciated as I am at my wits end.

Cheers in Advance
SooPa_fLy
Title: Re: Batch to run ping loop
Post by: QBasicMac on November 01, 2006, 07:40:13 AM
This worked when z.txt contained a few ip addresses, one to a line.

Lots of luck with your disk space if you run this for a long time. LOG will grow.

Mac

Code: [Select]
@echo off
cls
:loop
for /f %%I in (z.txt) do (
echo Pinging %%I
echo %TIME% >> z.log
ping %%I >> z.log
)
goto loop
Title: Re: Batch to run ping loop
Post by: GuruGary on November 01, 2006, 09:30:58 AM
How about:
Code: [Select]
ping -t 1.2.3.4Replace 1.2.3.4 with the IP address that you really want to ping.
Title: Re: Batch to run ping loop
Post by: QBasicMac on November 01, 2006, 09:58:07 AM
Evil, GuruGary! LOL

That will keep one IP busy. He could use START to get them all going.

But I don't think he wants THAT many pings. He said
Quote
Basically I want to ping an ip constantly to keep a connection going

So he needs to ping every minute or 10 minutes, etc., not every 10ms. If you know a way to do the QBasic equivalent of SLEEP 10, suggest that.

Mac
Title: Re: Batch to run ping loop
Post by: Aidy on November 01, 2006, 12:28:04 PM
would a simple way to do this be :

:ping
ping x.x.x.x
wait 10
goto :ping
Title: Re: Batch to run ping loop
Post by: SooPa_fLy on November 01, 2006, 02:36:57 PM
Basically my iplist.txt is going to have a few different ips so I don't give 1 website the sh!ts by constantly pinging them.
I am looking to send a ping out every few minutes to keep the connection established. while I try to figure out what another problem is.

Cheers for the replies guys.
Title: Re: Batch to run ping loop
Post by: QBasicMac on November 01, 2006, 06:00:08 PM
The "wait 10" idea doesn't work in WindowsNT. WAIT is not a command.

However, if you just want to stall to give hosts a break, try this

Use my suggested BAT file (change filenames as desired)

In the TXT file, put your real sites you want to ping and then follow by a zillion instances of your own IP address.

By the time it gets through trying to ping them, some time would have elapsed.
Title: Re: Batch to run ping loop
Post by: SooPa_fLy on November 01, 2006, 06:24:17 PM
Qbasic cheers for that I will give it a try.
What about this
:ping
ping -n 100 127.x.x.x
goto :ping

I have been pinging a mates website as he does not mind as I am having trouble making it find the txt file with the iplist.
Title: Re: Batch to run ping loop
Post by: GuruGary on November 01, 2006, 10:41:45 PM
At what interval do you want to ping your iplist.txt?  Do you want to wait between each ping?  Or ping everything in your iplist.txt, and then delay?

Try this for once every minute, delay between each ping:
Code: [Select]
@echo off
:Start
for /f %%a in ("C:\Documents and Settings\Matt\My Documents\Matt\iplist.txt") do (
   echo %TIME% >> pingLOG
   ping %%a >> pingLOG
   ping -n 61 localhost >NUL
   )
goto :Start
Title: Re: Batch to run ping loop
Post by: Fed on November 01, 2006, 11:36:47 PM
If you are just looking for a result without the nuts & bolts then Connection Keeper will do it all for you.
http://www.gammadyne.com/conkeep.htm
Of course you will learn a lot more talking to these scary dos guys. Hi fellas! :D
Title: Re: Batch to run ping loop
Post by: uli_glueck on November 02, 2006, 12:06:45 AM
Quote
would a simple way to do this be :

:ping
ping x.x.x.x
wait 10
goto :ping

use the "sleep" command from the [RK]

uli
Title: Re: Batch to run ping loop
Post by: QBasicMac on November 02, 2006, 11:16:18 AM
I would swear I just posted this, but I don't see it.
A bat file which can be named SLEEP.BAT and put in your path
Code: [Select]
@echo off
if x%1==x (
  echo Usage: SLEEP n [where n is the number of seconds]
  goto Adios
)
if not %1==NewCall %0 NewCall %1 >nul
ping -n %2 localhost
:Adios

SLEEP 10 will sleep 10 seconds.

Based on GuruGary's  ping -n 10 localhost >nul
which doesn't work on windowsNT for unknown reason

Mac

Title: Re: Batch to run ping loop
Post by: SooPa_fLy on November 02, 2006, 01:55:21 PM
Cheers for the tips guys. I will give them a go and see how it goes.

We have been running a ping utility but it is a trial and my manager wanted a bacth file.

Thanks again guys

cheers  :)