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

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.

Thanks
Gareth
0
gareth629
1 Solution

PrincipalCommented:
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.
pinglog12.txt
0

IT 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:

HTH,
Dan
0

Commented:
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"
0

IT 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.

0

Batchelor 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 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%

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.
1

IT ConsultancyCommented:
Thanks for selecting my answer, did you try it, got everything you need?

steve
0
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.