Solved

Batch script to parse list of IPs, ping then take action.

Posted on 2009-04-10
5
1,588 Views
Last Modified: 2013-11-10
I have a text file of a few hundred IP addresses. I want to read each IP from the file.
After I obtain the IP, I'll ping the address.
If the ping result is a success I want to run a whole bunch of other batch commands (I've got about 10 lines of code) - then go to the next IP in the text file when done.
If the ping result is a failure, just go to the next IP on the list.

I think I'm better off not posting my current code that doesn't work! Thanks guys.
0
Comment
Question by:ZabagaR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 24118390
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 150 total points
ID: 24118411
@echo off
for /F %%I in (iplist.txt) do (
  ping -n 1 -w 100 %%I >nul && (
     REM put your commands here, IP is %%I
  )
)
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 200 total points
ID: 24118416
this should do it...drop your code after the 'success' message
@echo off
for /f %%a in (ip.txt) do call :pingit %%a
goto :eof
 
:pingit
set ip=%1
ping %ip% -n 1
if %errorlevel%==0 goto success
goto :eof
 
:success
Echo %ip% success!

Open in new window

0
 
LVL 63

Assisted Solution

by:SysExpert
SysExpert earned 150 total points
ID: 24118421
0
 
LVL 15

Author Closing Comment

by:ZabagaR
ID: 31569048
SirBounty - that's the clearest answer for me. I actually was checking in to say I got the solution myself, similar to yours but instead of calling a local routine, I call another .bat and send my value to it as %1. I had already read 1 or 2 of the examples SysExpert sent - the first isn't any help but the last 2 are workable. But, I don't have a good understanding of the syntax. Same as Qlemo's input. I don't understand the double && or the use of the parenthesis. I'll have to look it up.

Thanks all !!  I really appreciate the quick replies. You guys and this site are great.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question