Solved

PInging by IP Address

Posted on 2009-06-30
4
246 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 14

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

21 Experts available now in Live!

Get 1:1 Help Now