Computing.Net > Forums > Programming > Batch file to ping several servers.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to ping several servers.

Reply to Message Icon

Name: Brogan
Date: November 1, 2005 at 17:33:01 Pacific
OS: WinXP
CPU/Ram: 256 mb
Comment:

I need a sample batch file that will ping several servers and send the results to a log file, with a time stamp as well.

If possible, it would be great if all i had to do was just plug in the IP addresses and move along. Please help me out if you can, i would appreciate it.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 1, 2005 at 20:28:09 Pacific
Reply:

Try this:

:: multiIP.bat
@echo off

for /f "tokens=*" %%I in (IPlist) do call :pinger %%I
goto :eof

:pinger

echo %TIME% >> pingLOG
ping %1 >> pingLOG
:: DONE


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Brogan
Date: November 2, 2005 at 03:58:37 Pacific
Reply:

Thanks for the help, now another question is do i have to create the log file first, or will it save it to it automatically?


0

Response Number 3
Name: Mechanix2Go
Date: November 2, 2005 at 05:01:56 Pacific
Reply:

It creates / appends the log file.

If you want a fresh log file for each "run" just change the first line to:

@echo off > pingLOG

which wipes the existing pingLOG



If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Brogan
Date: November 2, 2005 at 13:28:25 Pacific
Reply:

Ok, i copied and pasted the exact batch into notepad and saved it as multiIP.bat. I did substitute an actual IP address for (IPlist). Is that all i have to do? Because it's not working. Please let me know what else may need to be changed.

Thanks


0

Response Number 5
Name: Mechanix2Go
Date: November 2, 2005 at 21:35:25 Pacific
Reply:

Hi,

IPlist is the name of a file containing the IPs to ping.

Try that.


If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: Brogan
Date: November 3, 2005 at 03:26:28 Pacific
Reply:

ok, and just to be sure, should i keep the parenthesis with IPlist, and also do i need to put the path name with it, or just the IPlist?

Thanks.


0

Response Number 7
Name: Mechanix2Go
Date: November 3, 2005 at 04:07:44 Pacific
Reply:

Hi,

You need the parentheses.

And you need the path to the file if it's not in the current directory.

in (c:\temp\IPlist) do


If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: Brogan
Date: November 3, 2005 at 18:07:35 Pacific
Reply:

Ok, i hope this is the last question, cause i hate to keep bothering you, but it's still not working.

This is what i have in my "multiIP.bat" program:

@echo off

for /f "tokens=*" %%I in (C:\Documents and Settings\Ben\Desktop\batch\IPlist.txt) do call

:pinger %%I
goto :eof

:pinger

echo %TIME% >> C:\Documents and Settings\Ben\Desktop\batch\pingLOG.txt
ping %1 >> C:\Documents and Settings\Ben\Desktop\batch\pingLOG.txt
::DONE

I created a folder called "batch" on my desktop to hold these files. Let me know what i need to change, what needs to be added, etc.

Thanks again, you're a big help.


0

Response Number 9
Name: Mechanix2Go
Date: November 3, 2005 at 22:26:17 Pacific
Reply:

Hi,

Because of the spaces in the path, I beleive you'll need:

("C:\Documents and Settings\Ben\Desktop\batch\IPlist.txt")

The same goes for the other two instances of the path, in the :pinger.


If at first you don't succeed, you're about average.

M2


0

Response Number 10
Name: Brogan
Date: November 4, 2005 at 03:27:15 Pacific
Reply:

Man, i don't understand, it's still not working. What should the ip list have, just the addresses, or should it say ping in front of them, or anything else i'll need?

Also, should i leave the ".txt" with the file names?


0

Response Number 11
Name: Mechanix2Go
Date: November 5, 2005 at 00:23:07 Pacific
Reply:

The list of IPs needs just the numerical IPs, like this:

127.0.0.1
122.22.3.15

In answer to your last question, you can use any legal file name, with or without an extension.

Are you getting errors?

No pingLOG.txt?

Crash?


If at first you don't succeed, you're about average.

M2


0

Response Number 12
Name: Brogan
Date: November 5, 2005 at 07:14:46 Pacific
Reply:

no pinglog. it flashes the command prompt real quik and that's it.


0

Response Number 13
Name: Mechanix2Go
Date: November 5, 2005 at 08:26:58 Pacific
Reply:

Open a cmd prompt and run it so you can see what it's doing.


If at first you don't succeed, you're about average.

M2


0

Response Number 14
Name: Brogan
Date: November 7, 2005 at 12:16:56 Pacific
Reply:

It says it cant' find IPlist, even though i have it in the same folder as the .bat file. I've also tried putting the path with it, but that didnt' work either. very strange.


0

Response Number 15
Name: Mechanix2Go
Date: November 7, 2005 at 13:02:50 Pacific
Reply:

After the first line, which is:

@echo off

put these and post what you get:

type IPlist
pause


If at first you don't succeed, you're about average.

M2


0

Response Number 16
Name: Mechanix2Go
Date: November 7, 2005 at 13:48:24 Pacific
Reply:

It's bedtime for Buckwheat.

I'll check in tomorrow.


If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to ping several servers.

Batch File to Change Database .ini www.computing.net/answers/programming/batch-file-to-change-database-ini/14429.html

Batch File to Create a Shortcut www.computing.net/answers/programming/batch-file-to-create-a-shortcut/13374.html

Batch to Ping Help www.computing.net/answers/programming/batch-to-ping-help/15840.html