Solved

PInging by IP Address

Posted on 2009-06-30
4
248 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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