1

How can I ping a range of addresses starting with A and ending with B?

1
  • 5
    Do you mean Windows command line or really MS-DOS? – Dennis May 4 '12 at 19:14
4

You could use a for loop to ping each IP address one at a time, but this is incredibly slow.

for /l %i in (1,1,255) do ping -n 1 192.168.0.%i | find /i "Reply"
1

Here is how to do it with a 100ms timeout and neater output:

FOR /L %i IN (1,1,254) DO @ping -n 1 -w 100 192.168.1.%i | FIND /i "TTL"
2
  • Can you explain why this is better that the existing answers? – DavidPostill May 4 '17 at 19:05
  • The benefits of adding -w 100 results in the range being pinged in less time when many hosts within the range do not respond. Using 254 increments is appropriate for a /24 subnet as .0 and .255 would not need to be pinged. Brett has also called attention to this with a more aggressive value of 20 ms for the timeout. – TS79 Oct 27 '17 at 18:15
1

To speed up the admittedly slow answer above, and assuming the node you seek is on the lan or a fast wan, add a timeout to the ping (20 milliseconds here):

for /l %i in (1,1,255) do ping -w 20 -n 1 192.168.0.%i | find /i "Reply"

This is useful if you don't have a proper utility and you don't have a port or want to do a broad port scan, or if the client isn't listening on any port.

0

Lets better understand this command and how it actually works. The command

for /l %i in (1,1,255) do ping -n 1 192.168.0.%i | find /i "Reply"

says to: Do a loop of pings from 1, counting up 1 each time, until you reach 255, while waiting for only 1 response on the specified network of 192.168.0.XXX.

To specify From A to B is in the (1,1,255) part of the command. As (x,y,z) x represents your A value (or starting point for your range), y represents the count up amount to find the next value to attempt, and z represents the B value (or maximum end of your range).

Very useful command and what I do is I break up the command into 3 ranges, opening up 3 command prompts, and running all 3 ranges simultaneously to speed up the process, and to help with readability. Readability is why I ultimately started using 3 ranges, because running the full range command will yield results yes, but scrolling back up only goes back so far, making it only useful in short ranges.

Range 1-80:

for /l %i in (1,1,80) do ping -n 1 192.168.0.%i | find /i "Reply" 

Range 81-165:

for /l %i in (81,1,165) do ping -n 1 192.168.0.%i | find /i "Reply"

Range 166 to 255:

for /l %i in (166,1,255) do ping -n 1 192.168.0.%i | find /i "Reply"

Good Luck and Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.