Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-10
5
Medium Priority
?
1,595 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 71

Assisted Solution

by:Qlemo
Qlemo earned 600 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 800 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 600 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Make the most of your online learning experience.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

715 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