Need a batch for ping multipal IP

Hello Experts,
How does ping multipal server IP from a batch file, i need output of ping reply, route info (source interface)  & color in background (if TTL is up output should be in Green otherwise Red).

Example:-
C:\Users\MainLogin>ping -r 1 192.168.7.1

Pinging 192.168.7.1 with 32 bytes of data:
Reply from 192.168.7.1: bytes=32 time=31ms TTL=254
    Route: 3.3.3.1
Reply from 192.168.7.1: bytes=32 time=31ms TTL=254
    Route: 2.2.2.1
Reply from 192.168.7.1: bytes=32 time=37ms TTL=254
    Route: 1.1.1.1
Reply from 192.168.7.1: bytes=32 time=32ms TTL=254
    Route: 3.3.3.1
LVL 1
Rajat SehgalFounder Enhance TechnologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
powershell
$computers = get-adcomputer -Filter *| Select-Object -ExpandProperty name 
foreach ($computer in $computers){
if (Test-Connection -ComputerName $computer -Count 1 -Quiet){
  write-host ("{0}" -f $computer) -ForegroundColor Green
  }
  else {
  write-host ("{0}" -f $computer) -ForegroundColor Red
  }

}

Open in new window

output
0
Bill PrewCommented:
Have you considered using a utility to do this?  There are a lot of tools for pinging ranges or lists of computers, and reporting results, and a number of these are free or have a free version.  Might be more dependable and friendly than a script approach.

Here are a few I have used in the past, but a little google search will probably turn up some others, or some solution searching right here on Experts Exchange.



»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
I am to glad for your suggestion, but i need only batch process for the same.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bill PrewCommented:
What servers do you want to ping?  A defined IP range?  Or a list of server names from a text file?  Or other?


»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
We have iplist.txt
example:-
192.168.1.11
192.168.1.155
192.168.1.13
192.168.1.14
192.168.1.56
192.168.1.78
192.168.1.207
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Hello Experts,
Please suggest solution to my problem.
0
Bill PrewCommented:
If  the RED and GREEN colors for the different output conditions is a must have then I don't think you can do this with just a BAT script.  That capability doesn't exist there.  You can change the whole sessions window colors with the COLOR command, but not line by line.

You can do that with Powershell as David demonstrated, but since you didn't respond to his script it's hard to know at this point if Powershell is something you are comfortable with or not.


»bp
0
David Johnson, CD, MVPOwnerCommented:
change line 1
$computers = get-adcomputer -Filter *| Select-Object -ExpandProperty name
to
$computers = get-content iplist.txt
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Hello Bill Sir,
From my question i don't want change color of each lines i want ping reply along with route info output of each line  with colo background.
Ping.jpg
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Rajat,
Your last post confuses me, because it's all black&white — no colors. Do you mean that you're looking for output like this:

ping goodping bad
Regards, Joe
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Yes sir the same output i want.
ping-good.gif
ping-bad.gif
0
Bill PrewCommented:
Okay, here is a starting point of a BAT script.  It won't be as pretty as Powershell, but in case you are set on a BAT approach.  It uses ANSO escape sequences to control the output colors.  I have included color codes for a foreground approach, as well as a background color approach.  I prefer the foreground color approach, but you can decide for yourself, and adjust the BAT script as needed.

Save the attached file as a BAT script file (I had to rename it to attach and added a TXT extension, you don't want that when you rename it there), and run it from a DOS command line, passing it the name of a file that has the list of computers to ping (one per line).

EE29076489.bat.txt

Samples below show the output of a test here, the first with foreground coloring, then with background coloring.

Foreground coloringBackground coloring
»bp
1
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Bill,
When I run it here, I don't get color:

billprewcolorping
I didn't change anything in your script. Is there something that I need to do to "activate" color? Regards, Joe
0
Bill PrewCommented:
Joe, what version of Windows are you running?


»bp
0
Joe Winograd, Fellow&MVEDeveloperCommented:
W7 Pro SP1 64-bit with the latest updates.
0
Bill PrewCommented:
This is built into Windows 10, you really need to come over to the dark side Joe :-).

I think in Windows 7 you can load the ANSI.SYS driver for the command processor, but it is slightly different than the old C:\CONFIG.SYS days.  I believe it is now done as in this post:

How to Enable ANSI.SYS in a Command Window
ANSI.SYS can be loaded and used from the command prompt, with the restriction that it can run only in the context of the MS-DOS subsystem. Windows NT does not support ANSI escape sequences in Win32 Console applications. To load ANSI.SYS, add "device=c:\winnt\system32\ansi.sys" to the CONFIG.NT file in the Windows NT SYSTEM32 directory.

»bp
1
Joe Winograd, Fellow&MVEDeveloperCommented:
Thanks, Bill — works great in W10! I have two W10 sandboxes for testing the software that I develop, but there's no chance that I'll be using it anytime soon on my primary production box. You'll have to enjoy the dark side without me. :)

Fantastic batch script by you — as always! Regards, Joe

P.S. Opted not to enable ANSI.SYS in W7, so can't speak to that method.
0
Bill PrewCommented:
Thanks for the feedback Joe.  IMHO Windows 10 is the place to be now, but I don't want to take this thread sideways on that topic.  I don't like everything about it of course, but I don't see any reason not to be on it myself and take advantages of some of the the newer features.  That being said, ZtreeWin is still my goto file manager :-).


»bp
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Agree with not taking the thread sideways, but would also like to point out that Total Commander is still my go-to file manager. :)
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Hello David, Bill, Joe Sir,
Thank for your valuable suggestion.
We had implement & check, it working in Win 10.
But sir my query not solved yet we need separate output window for every IP with route info & red or green color output, please find example output.
Multi.jpg
0
Bill PrewCommented:
It would be helpful if you had specified a full and complete set of needs in the original question, it wasn't clear (at least to me) that you wanted multiple separate windows for each IP address.  In that case, that problem has already been solved here on Experts Exchange (it's always good to search the question history before posting a new question, there are a lot of good solutions on the site already).

This prior question should be very close to what you are now describing, take it and adjust as needed to get exactly what you want.



»bp
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Hmmm, interesting to note that the 14-Nov-2017 question that Bill references is by the same author as this one.
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Yeh i got that, even this batch i am using for multiple ping on daily basis in my office
MultiPingand we had try to implement / change this line
ping -n 1 -l 0 %~1 | find "TTL=" && (
to
ping -r 1 -l 0 %~1 | find "TTL=" && (
for getting same output but unable to get route info detail output in reply.
0
Bill PrewCommented:
Try adding the TRACERT command when PING indicates the node is up, as in below.  Adjust the TRACERT parms as needed for your use case.

@echo off
setlocal

set colorUp=2F
set colorDown=4F

if "%~1" EQU "" (
    exit /b
)

title IP:%~1 - Status:

:Loop
    echo %DATE% %TIME%
    ping -n 1 -l 0 %~1 | find "TTL=" && (
        color %colorUp%
        title IP:%~1 - Status:UP
        tracert %~1
    ) || (
        color %colorDown%
        title IP:%~1 - Status:DOWN
    )
    goto :Loop

Open in new window


»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Again thanks to you Bill sir,

According to you changes we had apply and getting output with complete trace route.
Ping with Trace Route
But sir i dont want complete traceroute output with ping, we need only source interface (example 1.1.1.2, 3.3.3.2). one by one TTL reply & interface info.
TTL & Route Info
0
Bill PrewCommented:
So, are you all set now?


»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Sir,
Still i am looking for ping reply output with source interface only.
0
Bill PrewCommented:
ping reply output with source interface only
Not sure what this means, please clarify?  Is this output from the PING command, or an option for it?  Or output of some other command?


»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Sir,
I want ping reply this type only.
Reply from 192.168.207.111: bytes=32 time=1ms TTL=64
    Route: 2.2.2.2
Reply from 192.168.207.111: bytes=32 time=1ms TTL=64
    Route: 2.2.2.2
Reply from 192.168.207.111: bytes=32 time<1ms TTL=64
    Route: 2.2.2.2
Reply from 192.168.207.111: bytes=32 time<1ms TTL=64
    Route: 2.2.2.2


Your last solution given me output :-
Reply from 192.168.207.111: bytes=32 time=1ms TTL=64

Tracing route to 192.168.207.111 over a maximum of 30 hops

  1    1 ms    <1 ms    <1 ms  192.168.90.1
  2   33 ms    32 ms    41 ms  3.3.3.2
  3   31 ms    41 ms    30 ms  192.168.207.111
 
Trace complete.
0
Bill PrewCommented:
How would that "Route: 2.2.2.2" be obtained?


»bp
0
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
ping -r 1 192.168.207.111

Reply from 192.168.207.111: bytes=32 time=1ms TTL=64
    Route: 1.1.1.1
Reply from 192.168.207.111: bytes=32 time=1ms TTL=64
    Route: 1.1.1.1
Reply from 192.168.207.111: bytes=32 time<1ms TTL=64
    Route: 1.1.1.1
0
Bill PrewCommented:
Okay, give this a try.  If you don't want the date stamp just comment out that line, but it was in the prior question solution...

@echo off
setlocal

set colorUp=2F
set colorDown=4F

if "%~1" EQU "" (
    exit /b
)

title IP:%~1 - Status:

set "TempFile=%TEMP%\%~n0.%~1.tmp"

:Loop
    echo %DATE% %TIME%
    ping -r 1 -n 1 -l 0 %~1>"%TempFile%"
    ping -r 1 -n 1 -l 0 %~1 | find "TTL=" <"%TempFile%" >NUL && (
        color %colorUp%
        title IP:%~1 - Status:UP
    ) || (
        color %colorDown%
        title IP:%~1 - Status:DOWN
    )
    findstr /r /v /i /c:"^$" /c:"Ping statistics" /c:"^Approximate" /c:"Packets:" /c:"Minimum =" /c:"^Pinging" <"%TempFile%"
    goto :Loop

if exist "%TempFile%" del "%TempFile%"

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rajat SehgalFounder Enhance TechnologyAuthor Commented:
Again Thanking You SIr
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.