[dba-Tech] Automate IP lookup

John Bartow john at winhaven.net
Fri Feb 27 18:08:06 CST 2009


Jon,
Vipre Enterprise has a function to do this - I believe this is what
"Enterprise Console" implies ;o) FYI half price for a competitive upgrade
:o)

Here's a script to ping a subnet. Takes a while and won't work if you have
personal firewalls set to not respond to a ping but I doubt that would be
the case.

HTH
John B
<code starts here>

@ECHO OFF 
@TITLE Ping Entire Subnet 
@COLOR 2F 
@IF NOT "%OS%"=="Windows_NT" GOTO :ERROROS 
GOTO :BEGIN 
:BEGIN 
::   SETLOCAL keeps all the variables in this script local to the script. 
SETLOCAL 
:: Don't forget to configure these four items. 
::
----------------------------------------------------------------------------
------------------- 
SET First_3_Octets=192.168.254
SET Starting_Number=1
SET Ending_Number=254
SET Output_Location=Pings.csv 
::
----------------------------------------------------------------------------
-------------------- 
ECHO Ping Entire Subnet>%Output_Location% 
Date /T >>%Output_Location% 
Time /T >>%Output_Location% 
ECHO.>>%Output_Location%
ECHO PingChecking... 
FOR /L %%i IN (%Starting_Number%,1,%Ending_Number%) DO (SET Last_Octet=%%i)
& (CALL :PingChecker) 
ECHO Run complete
ECHO.>>%Output_Location%
ECHO Processing Complete >>%Output_Location%
Time /T >>%Output_Location%
START /normal Notepad.exe %Output_Location%
ENDLOCAL
EXIT

:PingChecker
SET response= 
FOR /F "tokens=1,2,3 delims=:" %%i in ('ping -n 1
%First_3_Octets%.%Last_Octet%^| find "Reply"') DO (SET response=%%i) 
IF /I "%response%"=="Reply from %First_3_Octets%.%Last_Octet%" (GOTO :Reply)
:: ELSE (GOTO :NoReply)

:Next 
GOTO :EOF 

:Reply
ECHO %First_3_Octets%.%Last_Octet%, reply
ECHO %First_3_Octets%.%Last_Octet%, reply>> %Output_Location%
GOTO :EOF

:NoReply
ECHO %First_3_Octets%.%Last_Octet%, no response
ECHO %First_3_Octets%.%Last_Octet%, no response>> %Output_Location%
GOTO :EOF

:ERROROS 
ECHO This script requires the Windows NT O/S. Script will exit now. 
PAUSE 
CLS 
EXIT




More information about the dba-Tech mailing list