Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Making a simple batch file to ping computers.

Options
  • 03-02-2009 6:17pm
    #1
    Moderators, Regional Midwest Moderators Posts: 11,117 Mod ✭✭✭✭


    Well, not so simple. I am very rusty on the command line it seems. I have 11 computers which connect to two servers. I want to run a batch file on both servers that will ping each of the other 11 computers in turn, repeat untill I quit it (or maybe 24 hours), and output the result into a text file.

    From searching around the internet, I came across this example.
    :around
    PING -n 1 1.0.76.31 >>C:\Share\ping.log
    PING -n 1 1.0.76.32 >>C:\Share\ping.log
    PING -n 1 1.0.76.33 >>C:\Share\ping.log
    PING -n 1 1.0.76.34 >>C:\Share\ping.log
    PING -n 1 1.0.76.35 >>C:\Share\ping.log
    PING -n 1 1.0.76.36 >>C:\Share\ping.log
    PING -n 1 1.0.76.37 >>C:\Share\ping.log
    PING -n 1 1.0.76.38 >>C:\Share\ping.log
    PING -n 1 1.0.76.39 >>C:\Share\ping.log
    PING -n 1 1.0.76.40 >>C:\Share\ping.log
    PING -n 1 1.0.76.41 >>C:\Share\ping.log
    TYPE NUL | CHOICE.COM /N /CY /TY,60 >NUL
    goto around
    

    I know the 60 in the last part is to repeat every 60 seconds.

    What i'd like to get is the batchfile to display its progress, eg pinging computer1 at whatever time/date, Reply from computer1: bytes=32 time<1ms TTL=128, followed by 2,3,4 etc, maybe wait a moment, and repeat the process.

    Thanks for any help.


Comments

  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    1. You may want to put -w 5000 in your ping command so it times out after 5 seconds

    2. For putting in the time and date you can do: ECHO %TIME% %DATE% >>C:\Share\ping.log

    Is your choice command working? It's not in some versions of windows. If your choice command isn't working you can simulate it by doing "PING 1.2.3.4 -n 1 -w 60000 > NUL" where 1.2.3.4 is a host that is definitely not up.


  • Registered Users Posts: 5,379 ✭✭✭DublinDilbert


    i'm not sure if ping returns an exit code if its been successful or not, i would guess that it does.... in which case you can use the ERRORLEVEL keyword in the batch file

    It would probably look something like this:-
    IF ERRORLEVEL 2 echo "got a responsce"


  • Registered Users Posts: 507 ✭✭✭bigbadcon


    I wrote a small .net app recently to do this.

    Send me a PM if your interested and il send it on..


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    bigbadcon, please read the forum charter in regards to asking for private messages in thread. Many people will discover this thread via the search engines and instead of finding a solution they'll find you're request for a pm with is a dead end (hence the rule).

    E.P.


  • Registered Users Posts: 507 ✭✭✭bigbadcon


    Ok.couldnt really post code though cause its way too big.

    Probably should have pm'd OP myself..


  • Advertisement
  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    You can attach files to your posts too. Use the paperclip icon on the Reply to Thread page.


Advertisement