Link to home
Start Free TrialLog in
Avatar of ktancl88
ktancl88Flag for Singapore

asked on

A PING Batch File

Hi,
I want to create a bat file that I can ping to several servers.
I have tried
%echo off%
PING 10.204.1.35    but seem like doesn't work.    
Avatar of leegclystvale
leegclystvale
Flag of United Kingdom of Great Britain and Northern Ireland image

@echo off
ping 10.4.6.7
Avatar of ktancl88

ASKER

Hi,
it didn't work.
I name it as ping.bat but when i double click on it. It show a blank screen.
for multiple servers just add another line
@echo off
ping www.yahoo.com
ping www.microsoft.com
ping www.google.com
you won't get a reply from Microsoft
Where are you running it from? What path?
No good, it show me a blank screen after i double click on the bat file
start > run > cmd
i my place my ping.bat in c:\
try it on the desktop.
Do you have admin rights?

ping.doc
ok I do have a ping batch file that reads from a file and pings all name/address and give you a basi report.

:: multiIP.bat
@echo off

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

:pinger
     
Ping -n 2 -w 100 %1  >> results.txt
echo %1            %TIME%  >> results.txt    
echo *************************************************** >> results.txt
:: DONE


make a file in the same folder called names.txt and add one server address per line

it will create a result file (not very nice formated I give you) with the results

however I would serch for freeping by tools forever as this is a great tool where you can add the servers you want and it will give you a running report on how they reply

or look up angryip scanner if you want to scan a range of ip's by pinging

PS you get a black screen because you have run the echo off command..

try replacing it with echo on and you will see the results.
Hi, where would the results.txt placed ?
in the same folder as you run the batch file from

if you want simple change the line in the file to
echo *************************************************** >> c:\results.txt
or any other path you have rights to use.

(Dam i wish you could edit posts after you made them)
nope, is not working, can't locate result.txt
ok well it works perfectly on my PC.

click start,
run cmd to get a command prompt

drag and drop the batch file in to the window  (short cut to enter in teh path to a batch file)

hit return and see what the error message says.

I would also suggest changing the echo off to read echo on

Try echo >>c:\results.txt
for a bit of info,

echo >> "file name"  will append to a file (or create it if it is not currently there and apend to it)
echo > "file name" will over write the data in a file.

now the out put should look some thing like bellow. (as you can see bad formatting)

what do you need this batch file for?
I wrote it ages ago and never bothered to tidy it up.


Ping request could not find host PRI0313. Please check the name and try again.
 
PRI0313		10:58:18.55      
*************************************************** 
Ping request could not find host PRI0570. Please check the name and try again.
 
PRI0570		10:58:20.84      
*************************************************** 
Ping request could not find host PRI0575. Please check the name and try again.
 
PRI0575		10:58:23.13      
*************************************************** 
 
 
Pinging PRI0595.abc.acb.com [192.168.1.1] with 32 bytes of data:
 
 
 
Reply from 148.253.117.98: bytes=32 time<1ms TTL=64
 
Reply from 148.253.117.98: bytes=32 time<1ms TTL=64
 
 
 
Ping statistics for 148.253.117.98:
 
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
 
Approximate round trip times in milli-seconds:
 
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
 
PRI0595		10:58:24.15      
*************************************************** 
Ping request could not find host PRI0600. Please check the name and try again.
 
PRI0600		10:58:26.44      
*************************************************** 
Ping request could not find host PRI0610. Please check the name and try again.
 
PRI0610		10:58:28.73      
*************************************************** 

Open in new window

rename this file from working.txt to working.bat
working.txt
SOLUTION
Avatar of Rob Williams
Rob Williams
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
From an earlier post of mine, if of some value:

I put the following together. It should test your connection for you (>1/sec), however careful, it is pretty crude. It runs forever until you press Ctrl+C, but it makes no log entries until there is a disconnect. However, if the cable is disconnected for long it will fill the log very quickly. You might want to put some limits on it but I didn't have time right now. To run you need a tiny utility called Alive, as explained in the batch file. Just save with a name like Connect.bat and run by entering Connect <IP address>  e.g.  Connect 123.123.123.123  It will create a log file in the same folder named IPlog.txt with basic diagnostics as to why the disconnect.
Hope it is of some help.


Echo Off
Cls
Set TestIP=%1%
:: Download a little app called Alive from  http://wettberg.home.texas.net/alive.htm
:: Extract the files to a directory with this batch file and run using 'FileName <IP address>'
::  (see the Alive.txt file for an explanation of the app)
Echo.
Echo Note: This batch file will run FOREVER and if the cable is disconected for any
Echo  length of time, it will great a very large log very quickly.
Echo.
Echo  Press Ctrl+C  to exit
Pause

If Exist IPLog.txt Del IPLog.txt
Echo IP monitoring started %Date:~0,12% %Time:~0,5% >>IPLog.txt

:NEXT
ALIVE /Timeout=3 %TestIP%
If ErrorLevel 255 GoTo E255
If ErrorLevel 8 GoTo E8
If ErrorLevel 7 GoTo E7
If ErrorLevel 6 GoTo E6
If ErrorLevel 5 GoTo E5
If ErrorLevel 4 GoTo E4
If ErrorLevel 3 GoTo E3
If ErrorLevel 2 GoTo E2
If ErrorLevel 1 GoTo E1
GoTo NEXT
:E1
Echo %Date:~0,12%  %Time:~0,5% Request timed out >>IPLog.txt
GoTo NEXT
:E2
Echo %Date:~0,12%  %Time:~0,5% Destination host unreachable >>IPLog.txt
GoTo NEXT
:E3
Echo %Date:~0,12%  %Time:~0,5% Destination network unreachable >>IPLog.txt
GoTo NEXT
:E4
Echo %Date:~0,12%  %Time:~0,5% Destination protocol unreachable >>IPLog.txt
GoTo NEXT
:E5
Echo %Date:~0,12%  %Time:~0,5% Destination port unreachable >>IPLog.txt
GoTo NEXT
:E6
Echo %Date:~0,12%  %Time:~0,5% Hardware error >>IPLog.txt
GoTo NEXT
:E7
Echo %Date:~0,12%  %Time:~0,5% TTL expired in transit >>IPLog.txt
GoTo NEXT
:E8
Echo %Date:~0,12%  %Time:~0,5% Bad Destination  >>IPLog.txt
GoTo NEXT
:E255
Echo %Date:~0,12%  %Time:~0,5%  Unknown errors  >>IPLog.txt
GoTo NEXT
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial