Solved

PInging by IP Address

Posted on 2009-06-30
4
247 Views
Last Modified: 2012-05-07
Hi guys hope you are well and can help.

I currently run this script by determining if a host is up by pinging its hostname.
What i would like to do though is modify the below script to instead pinging by hostname, ping by its ip address.
Any help greatly appreciated.
@echo off
setlocal enabledelayedexpansion
for /f %%c in (computers.txt) do (
  call :GETINFO %%c
  echo %%c: !Availability!>>availability.txt
)
goto :eof
 
:GETINFO
if [%1]==[] goto :eof
Set Availability=
ping %1 -n 2 -w 100 >nul 2>&1  
If %errorlevel%==1 goto DOWN
 
echo %1: Up
Set Availability=Up
goto :eof
 
:DOWN
echo %1: Down
Set Availability=Down

Open in new window

0
Comment
Question by:Simon336697
4 Comments
 
LVL 15

Accepted Solution

by:
Giovanni Heward earned 200 total points
ID: 24752368

@echo off
setlocal enabledelayedexpansion
for /f %%c in (computers.txt) do (
  call :GETINFO %%c
  echo %%c: !Availability!>>availability.txt
)
goto :eof
 
:GETINFO
if [%1]==[] goto :eof
Set Availability=
for /f "tokens=1-6 delims=[.] " %%a in ('ping %1 -n 1 ^| find "["') do set ip=%%c.%%d.%%e.%%f
ping %ip% -n 2 -w 100 >nul 2>&1  
If %errorlevel%==1 goto DOWN
 
echo %1 [%ip%]: Up
Set Availability=Up
goto :eof
 
:DOWN
echo %1 [%ip%]: Down
Set Availability=Down

Open in new window

0
 
LVL 21

Assisted Solution

by:AmazingTech
AmazingTech earned 200 total points
ID: 24752446

@echo off
setlocal enabledelayedexpansion
for /f %%c in (computers.txt) do (
  call :GETINFO %%c
  echo %%c [!ip!]: !Availability!>>availability.txt
)
goto :eof
 
:GETINFO
if [%1]==[] goto :eof
Set Availability=
for /f "tokens=2 delims=[]" %%a in ('ping %1 -n 1 ^| find "["') do set ip=%%a
ping %ip% -n 2 -w 100 >nul 2>&1  
If %errorlevel%==1 goto DOWN
 
echo %1 [%ip%]: Up
Set Availability=Up
goto :eof
 
:DOWN
echo %1 [%ip%]: Down
Set Availability=Down

Open in new window

0
 
LVL 28

Assisted Solution

by:Bill Bach
Bill Bach earned 100 total points
ID: 24759307
I hate to ask the obvious question here, but... WHY???

The solutions provided to ping the server by IP address need to ping by name first to ascertain the host name.  At that point, why are you wasting time with the ping by IP address?

If you are having a problem with DNS, then the machine may ALSO be unreachable, and it is VERY important to know that pinging by HostName is failing.  If pinging by hostname fails, but pinging by address succeeds, is the system really functional?  What if a second server came up with the same hardcoded IP address?  This would seem to say that a PING by IP address might succeed even if the expected hostname computer were unavailable.

Maybe you have some need that I am just not able to comprehend, but I'm always trying to learn, too.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24783897
Thanks guys to all 3 of you.

Bill, nslookup is a DNS-specific lookup tool, which is why id prefer to use that instead of ping.

The other thing about using nslookup is that you can query the DNS database without the machine being online.

Thanks to all of you really appreciate all your help.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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