Solved

PInging by IP Address

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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