Have you ever needed to find a free IP address in a given range? Or, have you ever needed to find out which IP addresses in a range are in use? Sure, you can type a bunch of PING commands and note the results. Or, you can loop it:
for /l %i in (96,1,111) do @ping -n 1 10.1.0.%i | find "bytes="
Simply replace the “96” and “111” with the start/end range, and “10.1.0” with the subnet of your choosing. The “1” in the range is the counter, so if you want to skip values, simply change this number. The output will only list those devices which receive a reply from the PING.
If you have multiple subnets, you can loop the loop, like this:
Or, if you want it all in a fancy batch file, paste the following into a batch file (I call it “pingall.bat”).
@echo off if "%3" EQU "" ( echo pingall.bat ^<networkip^> ^<startip^> ^<endip^> [step] goto :eof ) setlocal set networkip=%1 set startip=%2 set endip=%3 set step=%4 if "%step%" EQU "" set step=1 for /l %%i in (%startip%,%step%,%endip%) do ping -n 1 %networkip%.%%i | find "bytes=" endlocal
To run this, you specify the network (class C only in this example), the start IP, the end IP, and optionally the step (which defaults to 1). Your execution will look something like this.
C:\utils>pingall.bat 10.1.2 211 215 Reply from 10.1.2.214: bytes=32 time<1ms TTL=128 Reply from 10.1.2.215: bytes=32 time=2ms TTL=64
It’s a quick way to see what’s online in an IP range — and sometimes, that’s exactly what you are looking for.