A Geek Tip from the Windows Command Line

Today’s tip is for the true geek who enjoys spending time in the command window. A few tips ago, we discussed the virtues of "pathping" to analyze the path between two IP addresses. But what if you want to make sure a block of IPs are responding? You could ping them all manually, or you could use the following little beauty:

echo off & for /l %n IN (1,1,254) do ping 192.168.1.%n

Let’s dissect the command. The first three elements (echo off &) are actually the first of two commands and are optional. It simply makes the output a little neater. The for loop has the following structure: FOR %variable IN (set) DO command The/l parameter specifies the type of number set used by the loop (in this case, a series of numbers defined by the contents of the parenthesis (1,1,254)). What this tells the for loop is to number a series from 1, incremented by 1 and through number 254. The ping command is the action taken by the for loop. The for loop substitutes a series of number variables as the last part of the IP address through each loop.

So that’s all there is to it. If you find this tip useful, you are hopefully considering making a batch file out of it. If so, remember to use double percent signs on the variables.

Leave a Reply