• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

Batch file to run ping

hi all,

I have a client who is having some intermittent network issue but it is proving difficult to tie down as every time I look all is fine. So..... what I would like to do is place a batch file on her desktop to do the following:

Ping www.google.ca for 10 minutes and output the result to google.txt file
Ping her default gateway for 10 minutes and output the result to router.txt file
Ping another host on the network for 10 minutes and output the result to host.txt file

All I would want her to do is double click the file and carry on with her work. I can take a look at the 3 text files later.

I would like all pings to run at once.

1 Solution
Fred MarshallPrincipalCommented:
I run this one all the time i.e. continuously and start it when the computer boots.  It's a little different than what you want.  But, you can run 3 instances of it - one for each target address.  If I recall, you will want to rename the target log files in each one so there's no conflict in writing to them.
Dan CraciunIT ConsultantCommented:
I'm sure there will be some experts that will provide you with the solution you need.
I just want to make a suggestion: instead of ping use hrping ( https://www.cfos.de/en/ping/ping.htm ) .
It has a -T option that will output a timestamp on each line. Very useful in doing something like this:
hrping google.ca -t -T > google.txt

And to add one more caution.  Ping can sometimes act as a keep alive resulting in the line staying up for the 10 minutes it is running and then dropping when the line goes "idle"
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Steve KnightIT ConsultancyCommented:
Probably a bit more than you want but I have a script of mine here which you can get it to ping a list of hosts every so often, and log it.  Together with second script you can schedule or get her to run which emails you the log file.

QlemoBatchelor and DeveloperCommented:
Performing Ping tests isn't something you can rely on. But if you do not have anything better, they can give you a starting point.
@echo off
setlocal EnableDelayedExpansion

set targets=www.google.ca
set log=c:\temp\ee\pingresults.log

for /L %%I in (1,1,36000) do ^
for %%T in (%targets) do (
   ping -n 1 -w 100 %%T >nul && set ok=y|| set ok=n
   echo %date% %time% %%T - !ok! 
) >> %log%

Open in new window

This will log into a single file, with a timeout of 100 ms per ping, and then wait one second; repeated for about 10 minutes. Each ping will have a timestamp.
Steve KnightIT ConsultancyCommented:
Thanks for selecting my answer, did you try it, got everything you need?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now