Monday, July 18, 2011

How to check PING command on a group of IPs

Here is a small DOS script that can ping a group of IPs...
In this example, we are trying to ping from 10.125.56.125 to 10.125.56.150 range.

Things which is important and must be remember is 'ENABLEDELAYEDEXPANSION' which is used for 'delayed expansion' for '!' mark (%var% ==> !var!)



@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set ip=10.125.56.1
for /L %%i in (25,1,50) do (
set add= %ip%%%i
ping !add! -n 1 > nul
set ret=!ERRORLEVEL!
if !ret!==1 (
echo Host not reachable : !add!
)
)

No comments: