ping and output a list of ip's

AlfonsoPina
AlfonsoPina used Ask the Experts™
on
I need something fairly simple, I just need to ping a list of computers on my text file (printers.txt) with a -a argument to resolve the hostname. then output that to a simple text file, output.txt

I have tried the following but the result was that I had 4k instances of cmd.exe in my processes.

@echo off

type nul>pass.txt

type nul>fail.txt

for /f %%a in (printers.txt) do call :ping %%a

goto :EOF

:ping

echo testing %1

ping %1|find /i "TTL=">nul

if %errorlevel%==0 echo pass&echo %1>>pass.txt

if %errorlevel%==1 echo FAIL&echo %1>>fail.txt


again, I ended up with about 4k instances of cmd.exe and find.exe (a grep instance of some sort).

I'm not real smart but I would like some assistance on this. I just want a very simple ping -a and output to a text or.csv file.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It's not so easy to accomplish this with a batch file.
I have created a Visual Basic script for this task.

Unpack PingComputer-1.zip and copy the files to a new directory.

Place the IP-addresses from "printers.txt" in "PingComputer.txt", one IP-address per line.
Run "PingComputer.cmd" which will execute "PingComputer.vbs" with cscript.exe
The output will be written to "PingComputer_Output.csv" in the same directory as the script.
PingComputer-1.zip
AlfonsoPinaSr. Systems Administrator

Author

Commented:
Thanks, I'm not very good at coding, a little c++ and java but no vbs at all. This solution helped me, I will probably use it all week long. Thanks again.
You are very welcome and good to know that it's working fine. Thanks for the grade.

Commented:
I suspect your batch file you might have called PING.cmd or PING.bat perhaps and therefore it looped and re-ran itself?

I know you have an answer, but for anyone wanting a batch solution too I have a few here of mine, a variation of the one I use a lot when no other methods are available to monitor certain kit is reachable and email me if not...

http://scripts.dragon-it.co.uk/links/batch-monitor-ping-email
http://scripts.dragon-it.co.uk/links/batch-ping-check-hosts
http://scripts.dragon-it.co.uk/links/batch-ping-list-of-hosts

Steve
AlfonsoPinaSr. Systems Administrator

Author

Commented:
thanks Steve, I hadn't thought of that but i suspect you are correct. I will take a look at my batch file and see if I can put a restriction on it somehow.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial