PDA

View Full Version : How do you make a Ping batch file?

Susan B
21-06-2002, 01:13 PM
I often need to ping a website to see if it is working OK and want a ping batch file to make it easier. What should be in it? At the moment I've got the following example and it doesn't appear to work:

@echo off
cd \
ping www.pcworld.co.nz

Have also tried just ping www.pcworld.co.nz but it won't stop then!

Any ideas?

Babe Ruth
21-06-2002, 01:31 PM
Susan,
The PING command options/switches are here:
and further down I have stuck a quick example (without any switches)
Cheers, Babe.

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] target_name

Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.

eg for me i have a pinger.cmd file very simple looks like:

@echo off
ping %1

The %1 is the host parameter passed when running the command e.g.

PINGER www.idg.co.nz

Could also do something like:
@echo off
:reping
ping %1
sleep 60
goto reping

In the second example the sleep command is used to 'wait' for a minute
before repinging the host passed as parameter 1

Brent P
21-06-2002, 01:49 PM
Leave off the www. Ping the host - pcworld.co.nz, microsoft.com, etc.

You can ping from the command prompt which will work fine now. If you want a batch file that will work from Run on the start menu try:

ping %1
pause

If you call it pingbat.bat then from run, you can enter
pingbat host - eg pingbat microsoft.com
and it will ping the site and wait for the key press before exiting.

Graham Petrie
21-06-2002, 01:55 PM
excuse me people, but why have a batch file to execute a command that is four letters long, replacing it with pingbat (7 letters!) I would just open a prompt and type ping pcworld.co.nz. Why do the same thing then type bingbat pcworld.co.nz???

G P

Babe Ruth
21-06-2002, 02:11 PM
Although Graham most of the time I use a PING command I am also using a number of the options/switches (usually the same ones) in which case a CMD file and pass the address as the param is great, also have the output sent to a file or grep'd. But everyone to their own.

Just a nickels worth,
Cheers, babe.

Susan B
21-06-2002, 02:30 PM

The reason I don't use ping from the run box is because the results flash by so quick and the window doesn't hang around long enough for me to read it. Someone once told me to go to a DOS window and run from there, which works fine. I'm just sick of opening a DOS to run it everytime I need it.

Babe, I've created and run a pinger.cmd file but get told "file not found" and can't run it. Same with pinger.bat now, whereas the bat file opened before even though the ping didn't work. ?:|

I notice that *.cmd files aren't associated with anything and can't see MS-DOS in the list of files to open with.

I'm stumped now!

Graham Petrie
21-06-2002, 02:48 PM
i just made a file entitled test.bat. It contains two lines of text.

@echo off
ping www.pcworld.co.nz

In a command window I type test [enter] and it works perfectly.

No idea Susan

G P

Billy T
21-06-2002, 03:09 PM
Hi Susan

I often need to use Ping so I keep a DOS box shortcut on my desktop. I agree with other repondents that a batchfile is an unnecessary complication.

To repeat a ping, press F3/enter, to get rid of a screen full of pings type cls/enter, and to go back to windows type exit/enter.

Sweet!

Cheers

Billy 8-{) ;) :)

-=JM=-
21-06-2002, 03:12 PM
Why bother with a batch file.

For such a simple task it is much more convenient to create a shortcut.

When on the desktop, right-click and select to have a new shortcut.
Set it to point to "ping www.pcworld.co.nz" and all is done.

For easiest use place this short cut in the quick launch area.

Babe Ruth
21-06-2002, 03:27 PM
Susan,
Sorry I forgot to ask what version/type Windows you are running...

The .CMD files are batch files for WinNT/2000/XP and .BAT files for all Windows versions.

If you are running NT/2000/XP you could have a command like:

cmd.exe /x /c ping pressf1.co.nz & pause

which could be in a shortcut of your choosing.

Cheers, Babe.

nzStan
21-06-2002, 03:37 PM
I use a Windows program called Ping Plotter. It has a dual function. It is actually a tracert program. You can set it to ping the address continually and it will chart the response time and display its current, highest and lowest ping time. Plus you can set alert parameters to email you or play a wave file on certain conditions.

Not sure if you are interested. You can download it from http://www.pingplotter.com/

Babe Ruth
21-06-2002, 03:38 PM
Sorry I didn't complete my last post and now I see JM's beat me to it.
The only thing I'd add would be the & pause after the bat (or cmd) file and the IP address to ping will at least leave the window open to enable you to see the results. Also you can add to my last post the fact you can do a TRACERT also on the same cmd line:

cmd.exe /x /c ping pressf1.co.nz & tracert pressf1.co.nz & pause

well whatever...
just a dimes worth
Cheers, Babe.

Susan B
21-06-2002, 03:42 PM
Why do I have to make life so complicated for myself? Duh! Don't know why I thought I needed a batch file, must be Fridayitis.

So far Billy's suggestion does the trick nicely - thanks for the F3 and cls tricks!

I also like JM's suggestion, but I'm back to the problem of the info whizzing by too quick. The path in the Target box is:
C:\WINDOWS\PING.EXE www.orcon.net.nz
Can I add something to the end of that to stop it disappearing on me?
A shortcut would do the trick nicely, of course.

And thanks for all your help people!

Susan B
21-06-2002, 03:43 PM
Babe, I'm using Win98 :-)

Graham L
21-06-2002, 05:21 PM
I suspect that you don't have ping.exe in your default path. Try a batch file which says:
@echo off
c:\path\to\prog\ping www.blah.com

That should work.

BTW someone suggested leaving off the "www" of the example sitename. That is a Bad Idea. It "works" in most *browsers*, but it actually slows you down. What happens is that your system doesn't know an IP address. It asks a DNS server. It doesn't know. It might aske a few DNS servers up the chain. The first DNS server tells your browser that it can't find the site. The *browser* knows it wants to do an HTTP, so it sticks "www" on the front and asks again. That might work (if the site actually has "www" in front of its name --- that is *not* compulsory). (The same applies to leaving off the "/" after the site name if you are not looking for an actual page (which has a .htm, .html, .shtml, etc extension --- and *must* not have the directory deliniter "/" after it). If the "/" is missing, the site hasn't *got* a page called by its sitename. It tells your browser, so the browser *adds* the "/" and tries again. It then will get the default page in that *directory* (index.html, or default.html).

Ping is not smart. It does what it is told. If you tell it a non-existent sitename, it *can't* find it. It does not know about any protocols except its own, and makes no assumptions about what sites "might" be called.

Graham Petrie
21-06-2002, 05:23 PM
Suan, can you open a DOS-prompt? type the ping command into the dos box. That way after it has finished, the box will still be there with all the info in it for you to view at your leisure.

ie Goto Start->Programs->DOS-Prompt Then type you ping command into the dos box.

G P

Graham Petrie
21-06-2002, 05:26 PM
Susan, can you open a DOS-prompt? type the ping command into the dos box. That way after it has finished, the box will still be there with all the info in it for you to view at your leisure.

ie Goto Start->Programs->DOS-Prompt Then type you ping command into the dos box.

G P

-=JM=-
21-06-2002, 06:09 PM
> Can I add something to the end of that to stop it disappearing on me?

Well that would explain your problem with the batch files. As far as I am aware the @echo off means that the box won't stay around.

nzStan
21-06-2002, 06:17 PM
I don't know why you still want to get this to work in DOS?

No fuss, no hassle, no retyping ip address or URLs, no F3 etc etc etc.

Billy T
21-06-2002, 06:23 PM
Congratulations Graham!

You seem to have managed the first genuine double-post. Heaps of the old version were imported when Press F1 data was switched across but we failed miserably in our attempts to double post during the beta testing.

Of course, it could just be your memory failing and you didn't realise you had already posted that message, I see there were three minutes between posts. ]:)

Cheers

Billy 8-{) :D :D :D

Graham L
21-06-2002, 06:33 PM
No, JM, @echo off just stops the command line from appearing twice on the screen. It's only an aesthetics thing: long batch scripts look very messy if you don't put that in. Whether or not the DOS window stays depends on the *Windows* settings, not on a batch command.

-=JM=-
21-06-2002, 06:45 PM
> Congratulations Graham!
>
> You seem to have managed the first genuine
> double-post. Heaps of the old version were imported
> when Press F1 data was switched across but we failed
> miserably in our attempts to double post during the
> beta testing.
>
> Of course, it could just be your memory failing and
> message, I see there were three minutes between
> posts. ]:)
>
> Cheers
>
> Billy 8-{) :D :D :D

Have a closer look Billy ;).

hmm so just who is Suan??

Graham Petrie
21-06-2002, 06:49 PM
Read my post re: Press F1 Bugs. this was the thread where it seemed my post didn't appear requiring me to logon - I then re-posted, and fixed the mistake with Susan's name as I did so. Then, both posts appeared! So, there is still a bug somewhere, but I did actually click post twice.

G P

Susan B
21-06-2002, 06:51 PM
Graham L, I'm delighted to inform you that you remain the undisputed PC/DOS expert of the Press F1 forum. :-) :-)

You hit the nail fair and square on its head. The batch file works brilliantly and does exactly what I want it to do. The ping.exe is in my Windows folder and I wasn't putting that path in the batch file.

Absolutely no ingratitude to all the others trying to help, I've learnt a heck of a lot here and nothing has been wasted. Thank you to all who have helped.

Graham P, yes I can open the DOS box and do all that, I just wanted a shortcut to double-click on and have it do it all for me, which I now have.

PS Graham L, there will be an email for you shortly.

Susan B
21-06-2002, 08:24 PM
Graham L, the email I sent you got bounced. :-(

I used the one that I contacted you with last time (with 'nuts' in it). If you still have my hotmail addy can you contact me?

It's not important though, and you don't have to if you don't want to.

-=JM=-
21-06-2002, 09:17 PM
> Read my post re: Press F1 Bugs. this was the thread
> where it seemed my post didn't appear requiring me to
> logon - I then re-posted, and fixed the mistake with
> Susan's name as I did so. Then, both posts appeared!
> So, there is still a bug somewhere, but I did
> actually click post twice.
>
> G P

It is not a bug of the forums. The post button was hit twice, so ofcourse it posted twice.

wuppo
21-06-2002, 09:48 PM
What Browsers automatically append a www to a url they can't resolve?

My understanding of whether a url requires a 'www' prefix to be resolved depends on the DNS entries.

If a DNS 'A' record contains a www prefixed url AND a 'CNAME' (alias) record exists for the URL without the www, the DNS service will respond to both versions. If there is no alias record, only the www prefixed address will be recognised. Hence some sites are only 'reachable' by their full www address, while others respond to both (with and without www).

Obviously, it has become the norm to provide an alias, so the www is not required.

Billy T
21-06-2002, 11:35 PM
It was tongue in cheek actually JM. It was clear that it was a second post and I was just rattling the cage to see who would bite. If we couldn't provoke a double post it wasn't likely to happen any time soon.

Cheers

Billy 8-{) :D :D

-=JM=-
21-06-2002, 11:45 PM
> It was tongue in cheek actually JM. It was clear
> that it was a second post and I was just rattling the
> cage to see who would bite. If we couldn't provoke a
> double post it wasn't likely to happen any time
> soon.
>
> Cheers
>
> Billy 8-{) :D :D

Well it took me a while to realise. I was sitting here going "now where is the difference". I kept looking at the end because that's usually where s difference would be.

robo
22-06-2002, 10:16 AM
I think all Susan was looking for was the pause so it didn't disappear directly if she used the run command. A batch file with:
ping %1%
pause
Been kind of interesting though.
robo.

Graham L
22-06-2002, 03:59 PM
Susan: I'll go upstairs now and see if anything got through. (it's 4nuts ...)

I'm going to have to work to beat your post-count. I'm up to less than 1% of what I had (according to someone who had a look after I told him about the site).

Addendum to DOS batch files: if you make a batchfile called runping.bat including a line like:
ping %1 %2 %3 %4
runping www.pressf1.co.nz -o -f -c:10
those arguments will be appended to the command. You could have:
ping %1 -o -f
to use a set of options which you always want, and add only the sitename.

You can give *up to* the number of "%n" arguments you have given in the file. There's a limit of 9 (which there is way around) . (If you include the line: echo %0 , it will print the name of the batch file. That is actually useful --- it's a DOS thing inherited from UNIX which is used a LOT in system programming).

Graham L
22-06-2002, 04:13 PM
wuppo, the www is *not* a prefix. It is a hostname . The rest of a sitename is the domain name. I do know about CNAMEs ... I've got a master and 2 slave DNS servers on my home network. I once understood DNS enough to write the tables. B-) Now I just copy entries.

I "seem to remember" having read "somewhere" that "some" browsers do this, in an effort to make things user-friendly. They certainly try to do this for the trailing "/" directory separator. It makes for more packets ... but as everyone knows there is infinite bandwidth now.

Graham Petrie
22-06-2002, 04:14 PM
Sorry, unclear. Bug was that my first post didn't seem to appear, so I posted again. The double post wasn't the result of a bug, but the reason posted twice was. Hope that clarifies it. I am happy to be the first pleb to be a little click-happy.

G P
:8)

wuppo
22-06-2002, 05:26 PM
Graham,
Not wanting to get into a war of semantics, but there are varying opinions on the definition of hostname. Heres one that disagrees with you:

hostname
1. (Or "sitename"). The unique name by which a computer is known on a network, used to identify it in electronic mail, Usenet news, or other forms of electronic information interchange.

On Internet the hostname is an ASCII string, e.g. "foldoc.doc.ic.ac.uk" which, consists of a local part (foldoc) and a domain name (doc.ic.ac.uk). The hostname is translated into an Internet address either via the /etc/hosts file, NIS or by the Domain Name System (DNS) or resolver. It is possible for one computer to have several hostnames (aliases) though one is designated as its canonical name.

Susan B
22-06-2002, 05:41 PM
Graham L, I tried another email message and it bounced again. Yes, used the 4nuts with your name. You can email me if you like: -t-o-p-a-z-z-1-0-@hotmail.com. Remove all of the hyphens first.

Thank you for the DOS batch files addendum, I'll have a good fiddle later. My main purpose for using ping is just to test that my internet connection is working OK as sometimes it stalls when first connecting and goes to sleep at other times.

Also, sometimes when trying to upload files to my websites the FTP program can't send them and the ping usually shows that the site is unreachable for some reason.

Don't worry about your post count, I'll be bombarding you with more DOS questions when I get my act sorted out and you'll have an opportunity to increase your tally then. ;-) :-)

Graham L
23-06-2002, 04:36 PM
Susan: my account with them 4nuts seems to be suspended --- maybe the mailbox has filled up. I'll try making another one ... need to grab a computer which I can use for more than 15 mins to do that. Tomorrow maybe.

Susan B
23-06-2002, 05:29 PM
> maybe the mailbox has filled up.

Yes, it will be full of Press F1 notifications!! ;-)

No hurry, just when you're ready. :-)

-=JM=-
23-06-2002, 05:54 PM
> Susan: my account with them 4nuts seems to be
> suspended --- maybe the mailbox has filled up. I'll
> try making another one ... need to grab a computer
> which I can use for more than 15 mins to do that.
> Tomorrow maybe.

May I ask why you can't use a computer for more than 15 mins?

Sounds as if you jump into other peoples houses and use theirs when they're not looking :p

Susan B
23-06-2002, 06:04 PM
> May I ask why you can't use a computer for more than
> 15 mins?
>
> Sounds as if you jump into other peoples houses and
> use theirs when they're not looking :p

That's almost exactly what he does JM! You obviously didn't read the muggie page properly or you wouldn't be asking that. :-(

-=JM=-
23-06-2002, 07:44 PM
> > May I ask why you can't use a computer for more
> than
> > 15 mins?
> >
> > Sounds as if you jump into other peoples houses
> and
> > use theirs when they're not looking :p
>
> That's almost exactly what he does JM! You obviously
> didn't read the muggie page properly or you wouldn't

Yes it did read all the info on that page. But am still lost as to why only for 15 mins.

Is it a library limit or something. Whenever I've been there, they don't seem to police it or anything.

Susan B
23-06-2002, 08:35 PM
I think Graham uses one to get his emails and another for posting here.

I suppose the email PCs must have a 15 minute limit as Graham said there's only two of them where he goes. The other ones on which he posts to here wouldn't have a limit.

Graham L
24-06-2002, 05:26 PM
The 15 minutes is the unit of charging for email and overseas internet access. There are two machines, one has a limit of 15 minutes. The other can be used for as long as you feed its card reader with electronic dollars. But I see that the price is being reduced from $4/hr to$3.

It won't be PressF1 emails -- I don't get them; I keep an eye on the threads. Even when I did, they didn't cause a problem. I purged a hundred or so, and I was still well inside the limit of disk space. It's probably someone who thinks that background music is a good idea. :-( Or I have been put on a list. X-(

This is totally irrelevant to the original posting, isn't it? ]:)

Susan B
24-06-2002, 05:35 PM
> This is totally irrelevant to the original posting,
> isn't it?

It's still educational though. :D

I'll keep trying but they're still getting bounced - the last one at 3:33pm today.

-=JM=-
24-06-2002, 07:09 PM
So you don't have a PC at home to use?

Graham L
25-06-2002, 05:29 PM
Only about 10 on my network... 8086 up to P133 plus microVax II, Apples, etc. A few more boxes to be put together.

mrbum123
13-01-2008, 04:00 PM
bet ya a nickle that he named it ping.bat, name it test.bat otherwise the ping command for some reason will loop endlessly

wratterus
14-01-2008, 08:31 AM
Hopefully they got it fixed about 6 years ago... lol.

spaldingfun
14-08-2008, 10:19 AM
Ping batch file is ever so simple, tried and tested by myself. If all you want to do is ping 1 or more ip addresses then open a new text file the type as follows

ping 192.168.1.69.
ping 192.168.1.68.
ping 192.168.1.63.
ping 192.168.1.64.
cmd

then save as pingtest.bat

you must make sure you put the dot at the end of each ip address and save, an icon will appear on your desktop, double click on it and away you go, easy as that, i promise.

wratterus
14-08-2008, 10:34 AM
OMG it's happened again.

Thanks.

:)

bevy121
14-08-2008, 11:09 AM
OMG it's happened again.

Thanks.

:)

How many times has this been asked.... but as usual, nothing is done.

:rolleyes: :dogeye:

chikop
04-12-2008, 02:18 PM
Cool.
I got exactly what I was looking for.
The conventional way of creating a batch file for other versions of windows using a notepad didn't work on my windows 2000 professional desktop PC.
The batch file created in this manner will just repeat ping command without showing out the ping results.

It took me almost an hour to search the internet to get to such a simple solution.

Thanks to you :)

Cool.
I got exactly what I was looking for.
The conventional way of creating a batch file for other versions of windows using a notepad didn't work on my windows 2000 professional desktop PC.
The batch file created in this manner will just repeat ping command without showing out the ping results.

It took me almost an hour to search the internet to get to such a simple solution.

Thanks to you :)

Why bother with a batch file.

For such a simple task it is much more convenient to create a shortcut.

When on the desktop, right-click and select to have a new shortcut.
Set it to point to "ping www.pcworld.co.nz" and all is done.

For easiest use place this short cut in the quick launch area.

chikop
04-12-2008, 02:20 PM
.

Chilling_Silence
04-12-2008, 02:23 PM
Actually, you *dont* need a . after the IP's, nor do you need to have "cmd" afterwards either. In fact, its probably better that you dont ...
Try saving something like this as a .bat file:

ping ihug.co.nz
pause

Bear in mind that if you're saving from within Notepad, its easiest if you put the name in speech marks, to *force* it to save it with the name exactly as you write it, such as:

"pingtest.bat"

chikop
04-12-2008, 02:32 PM
I tried this way too before but all it gives a blank command window i.e. no ping results shown. The method shown by -=JM=- works.