Solved

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

Posted on 2009-04-10
5
1,557 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
5 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 24118390
0
 
LVL 68

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now