Solved

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

Posted on 2009-04-10
5
1,581 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 85
Wild card search and replace using Notepad 7 69
Do Wend Macro not working 22 72
Does WMIC Have Capability to Turn on Windows Automatic Updates? 15 56
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

751 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