Actually, you probably want to replace the ">" quoted in my example to a ">>" as well.
Main Topics
Browse All TopicsHow do I create a batch file that will read a csv or txt file as input to ping a list of computers and then output a file of the computers that did not reply? I will not be pinging IP addresses; I will be pinging computer names. I've been using this as a batch script but it takes forever and then I have to hunt for all the bad computer names line by line.
@ECHO OFF
ping ORC11116413 -w 1000 > ping.txt
ping ORD11102296 -w 1000 >> ping.txt
Thanks in advance!
-Makila
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
DON'T USE PING.BAT - PING is the EXE you need to use. Windows checks the current directory for the command first - .bat, .exe, .com, etc - if found, it tries to use that one. So it never gets a chance to run correctly.
rename ping.bat to something like "pinglist.bat"
If you want to get fancy, you could say "pinglist names.txt" then in the script, change the for line to the following:
for /f "tokens=1" %a in (%1) DO @ping -n 1 -w 100 %a ^| find /i "request" >> ping.log
Here, I went a little nuts - see if you like this:
@echo off
If /i "%0" == "ping" Then Goto NameError
If /i "%0" == "if" Then Goto NameError
If /i "%0" == "for" Then Goto NameError
If /i "%0" == "find" Then Goto NameError
If /i "%0" == "type" Then Goto NameError
If /i "%0" == "echo" Then Goto NameError
If /i "%0" == "set" Then Goto NameError
if "%1" == "" Goto Usage
if /i "%1" == "showresults" Goto Usage
if /i "%1" == "alive" Goto Usage
If /i "%1" == "dead" goto usage
Set systemlist=%1
if /i "%2" == "alive" Set Criteria="Reply"
if /i "%3" == "alive" Set Criteria="Reply"
if /i "%4" == "alive" Set Criteria="Reply"
if /i "%2" == "dead" Set Criteria="Request"
if /i "%3" == "dead" Set Criteria="Request"
if /i "%4" == "dead" Set Criteria="Request"
if "%2" == "" SET LogFile=%0.log
if /i "%2" == "showresults" SET LogFile=%0.log
if /i "%2" == "alive" SET LogFile=%0.log
if /i "%2" == "dead" SET LogFile=%0.log
if exist ping.log del ping.log
for /f "tokens=1" %%a in (names.txt) DO @ping -n 1 -w 100 %%a | find /i "%criteria%" >> ping.log
if /i "%4" == "showresults" Type %logfile%
if /i "%3" == "showresults" Type %logfile%
if /i "%2" == "showresults" Type %logfile%
Goto End
:usage
Echo %0 SystemList.txt [logfile.log] [showresults] [alive^|dead]
echo.
echo Where SystemList.txt is a text file with system names or IPs, one per line.
Echo And logfile.log is the name of the log file to record the output to.
Echo Default log file is %0.log
Echo.
Echo showresults tells the script to display the log file upon script completion.
Echo.
Echo alive tells the script to output all systems that respond to the ping request.
Echo dead tells the script to output only the systems that do not respond to the
Echo ping request.
Goto End
:NameError
Echo The name of this script cannot be "PING" as the "PING" command
Echo is an integral part of the script. It cannot be named "IF", "FOR",
Echo "SET", "ECHO", "TYPE", or "FIND" either.
:end
Try this one - I think I debugged it:
@echo off
If /i "%0" == "ping" Then Goto NameError
If /i "%0" == "if" Then Goto NameError
If /i "%0" == "for" Then Goto NameError
If /i "%0" == "find" Then Goto NameError
If /i "%0" == "type" Then Goto NameError
If /i "%0" == "echo" Then Goto NameError
If /i "%0" == "set" Then Goto NameError
if "%1" == "" Goto Usage
if /i "%1" == "showresults" Goto Usage
if /i "%1" == "alive" Goto Usage
If /i "%1" == "dead" goto usage
Set systemlist=%1
if /i "%2" == "alive" Set Criteria="Reply"
if /i "%3" == "alive" Set Criteria="Reply"
if /i "%4" == "alive" Set Criteria="Reply"
if /i "%2" == "dead" Set Criteria="Request"
if /i "%3" == "dead" Set Criteria="Request"
if /i "%4" == "dead" Set Criteria="Request"
If "%criteria%" == "" Then Set Criteria="Request"
if "%2" == "" SET LogFile=%0.log
if /i "%2" == "showresults" SET LogFile=%0.log
if /i "%2" == "alive" SET LogFile=%0.log
if /i "%2" == "dead" SET LogFile=%0.log
if exist %logfile% del %logfile%
for /f "tokens=1" %%a in (names.txt) DO @ping -n 1 -w 100 %%a | find /i %criteria% >> %logfile%
if /i "%4" == "showresults" Type %logfile%
if /i "%3" == "showresults" Type %logfile%
if /i "%2" == "showresults" Type %logfile%
Goto End
:usage
Echo.
Echo %0 SystemList.txt [logfile.log] [showresults] [alive^|dead]
echo.
echo Where SystemList.txt is a text file with system names or IPs, one per line.
Echo And logfile.log is the name of the log file to record the output to.
Echo Default log file is %0.log
Echo.
Echo showresults tells the script to display the log file upon script completion.
Echo.
Echo.
Echo alive tells the script to output all systems that respond to the ping request.
Echo dead tells the script to output only the systems that do not respond to the
Echo ping request. dead is the default setting.
Goto End
:NameError
Echo The name of this script cannot be "PING" as the "PING" command
Echo is an integral part of the script. It cannot be named "IF", "FOR",
Echo "SET", "ECHO", "TYPE", or "FIND" either.
:end
New revision - don't think it will solve your problem, but try it anyway:
@echo off
REM PINGLIST.CMD - REVISION 3
If /i "%0" == "ping" Then Goto NameError
If /i "%0" == "if" Then Goto NameError
If /i "%0" == "for" Then Goto NameError
If /i "%0" == "find" Then Goto NameError
If /i "%0" == "type" Then Goto NameError
If /i "%0" == "echo" Then Goto NameError
If /i "%0" == "set" Then Goto NameError
if "%1" == "" Goto Usage
if /i "%1" == "showresults" Goto Usage
if /i "%1" == "alive" Goto Usage
If /i "%1" == "dead" goto usage
Set systemlist=%1
if /i "%2" == "alive" Set Criteria="Reply"
if /i "%3" == "alive" Set Criteria="Reply"
if /i "%4" == "alive" Set Criteria="Reply"
if /i "%2" == "dead" Set Criteria="Request"
if /i "%3" == "dead" Set Criteria="Request"
if /i "%4" == "dead" Set Criteria="Request"
If "%criteria%" == "" Then Set Criteria="Request"
if "%2" == "" SET LogFile=%0.log
if /i "%2" == "showresults" SET LogFile=%0.log
if /i "%2" == "alive" SET LogFile=%0.log
if /i "%2" == "dead" SET LogFile=%0.log
if exist %logfile% del %logfile%
for /f "tokens=1" %%a in (%systemlist%) DO @ping -n 1 -w 100 %%a | find /i %criteria% >> %logfile%
if /i "%4" == "showresults" Type %logfile%
if /i "%3" == "showresults" Type %logfile%
if /i "%2" == "showresults" Type %logfile%
Goto End
:usage
Echo.
Echo %0 SystemList.txt [logfile.log] [showresults] [alive^|dead]
echo.
echo Where SystemList.txt is a text file with system names or IPs, one per line.
Echo And logfile.log is the name of the log file to record the output to.
Echo Default log file is %0.log
Echo.
Echo showresults tells the script to display the log file upon script completion.
Echo.
Echo.
Echo alive tells the script to output all systems that respond to the ping request.
Echo dead tells the script to output only the systems that do not respond to the
Echo ping request. dead is the default setting.
Goto End
:NameError
Echo The name of this script cannot be "PING" as the "PING" command
Echo is an integral part of the script. It cannot be named "IF", "FOR",
Echo "SET", "ECHO", "TYPE", or "FIND" either.
:end
REM Cleanup
Set Criteria=
Set Logfile=
Set SystemList=
I ran it all these ways in the command prompt window and they didn't work:
pinglist2.bat names.txt ping2.log showresults
pinglist2.bat names.txt ping2.log showresults alive
pinglist2.bat names.txt ping2.log showresults dead
pinglist2.bat names.txt showresults
pinglist2.bat names.txt showresults alive
pinglist2.bat names.txt showresults dead
But if I leave the showresults out, it works fine. The names.txt is just a file with one computer name per line like:
computer1
computer2
computer3
Despite Leew getting the well earned points, here's just another script that you can run, it gives a slightly, more user-friendly output:
:====8<-----[ FileName.cmd ]-----
@ECHO OFF
TITLE Network Check
REM --------------------------
REM
SET MachineList=names.txt
SET ResultsFile=results.txt
REM
REM --------------------------
CLS
ECHO.
IF NOT EXIST "%MachineList%" (
ECHO Cannot locate Machine List: %MachineList%
PAUSE>NUL
GOTO :EOF
)
ECHO Processing all machine names in %MachineList% . . .
ECHO.
FOR /f "tokens=*" %%M in (%MachineList%) do CALL :CHECK "%%M"
GOTO :EOF
:CHECK
SET Machine=%~1
SET Machine=%Machine: =%
PING -w 1000 %Machine%>NUL
IF %ERRORLEVEL% NEQ 0 ECHO %Machine% did not respond at %Time%>>%ResultsFile%
EXIT /B
:EOF
:====8<-----[ FileName.cmd ]-----
HTH
[r.D]
Glad it helped, makila.
Hey Leew,
erm.. The best 'tutorial' that covers Errorlevels that I've come across, and learnt just about everything I know about them from, is: <at command line> type IF /?
It covers Errorlevels somewhere down there.
But there's really not too much to them. Here's the jist of them:
All programs return a number %ERRORLEVEL% that represents how the program performed. Typically, 0 = successful, -1 = failed. Obviously though, it differs with programs, and certain errorlevels mean different things.. typically.. Then, it's just a case of use 'NEQ', 'EQU', 'GEQ', etc, operators to process the errorlevels.
Here's a rather important note, that I *think* is covered in the 'IF /?' output:
IF ERRORLEVEL 0 ECHO Errorlevel is 0
(for example)
Most people use that command, and believe that it will ECHO "Errorlevel is 0" if the errorlevel *is* 0. However, it doesn't, when you use that syntax, it will perform the task (in this case, ECHO Errorlevel is 0) if the %ERRORLEVEL% is Greater than, or equal to 0. So, it will do that operation even if the ERRORLEVEL is 999. So, just be careful with that one, and you'll figure the rest ^_^
HTH
[r.D]
Business Accounts
Answer for Membership
by: leewPosted on 2005-01-05 at 12:57:07ID: 12966283
Make the list of computer names, one per line and save it in a text file. In the example below, I assume the text file is named "names.txt". Then run this command:
for /f "tokens=1" %a in (names.txt) DO @ping -n 1 -w 100 %a ^| find /i "request" > ping.log
The above command is for running in a command prompt. If you want to include this in a batch file, use %%a instead of %a