Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch to run ping loop  (Read 34223 times)

0 Members and 1 Guest are viewing this topic.

SooPa_fLy

  • Guest
Batch to run ping loop
« 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

QBasicMac

  • Guest
Re: Batch to run ping loop
« Reply #1 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
« Last Edit: November 01, 2006, 07:42:29 AM by QBasicMac »

GuruGary



    Adviser
    Re: Batch to run ping loop
    « Reply #2 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.

    QBasicMac

    • Guest
    Re: Batch to run ping loop
    « Reply #3 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

    Aidy

    • Guest
    Re: Batch to run ping loop
    « Reply #4 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

    SooPa_fLy

    • Guest
    Re: Batch to run ping loop
    « Reply #5 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.

    QBasicMac

    • Guest
    Re: Batch to run ping loop
    « Reply #6 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.

    SooPa_fLy

    • Guest
    Re: Batch to run ping loop
    « Reply #7 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.

    GuruGary



      Adviser
      Re: Batch to run ping loop
      « Reply #8 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

      Fed

      • Moderator


      • Sage
      • Thanked: 35
        • Experience: Experienced
        • OS: Windows XP
        Re: Batch to run ping loop
        « Reply #9 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

        uli_glueck

        • Guest
        Re: Batch to run ping loop
        « Reply #10 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

        QBasicMac

        • Guest
        Re: Batch to run ping loop
        « Reply #11 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


        SooPa_fLy

        • Guest
        Re: Batch to run ping loop
        « Reply #12 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  :)