Skip to content

Bash: Script to find active computers in a subnet using ping

by mat on January 27th, 2010

The following is a simple bash script that will scan each ip address in a give subnet and report if they are alive (or accepting ping requests). The code creates processes for each ping so that it completes quickly rather than scanning each ip address sequentially.

Create a text file called “” and paste the following into it:


: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}

for addr in `seq 0 1 255 `; do
#   ( echo $subnet$addr)
( ping -c 3 -t 5 $subnet$addr > /dev/null && echo $subnet$addr is Alive ) &

Save and close, then it can be called from the command line like so:

sh 192.168.1.

This will scan from to and will return something like the following: is Alive is Alive is Alive is Alive
  1. Your example will only scan and above. You need to change your sequence if you want .0 in there.

    for addr in ‘seq 0 1 255 ‘; do

  2. Ah good spot!

  3. anoop permalink

    just give while loop construction for pinging any subnet

  4. Use arping commad. Some machines may have firewall blocking ICMP-echo, but they will respond go arping.
    arping will also not work acros networks i.e. routers will block it.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS