Solved

PInging by IP Address

Posted on 2009-06-30
4
245 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
Comment Utility

@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
Comment Utility

@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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

12 Experts available now in Live!

Get 1:1 Help Now