//View Tip #629
Similar Tips
There are no more tips with these tags. Perhaps you'd like to submit one, or browse the archives.

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
On my home network I often need to know which IP addresses have devices connected to them. The following one-liner will scan a given range and let you know whether each IP can be pinged.

for IP in 192.168.1.{1..10}; do if ping $IP -c 1 > /dev/null; then echo $IP alive; else echo $IP dead; fi; done


View Comments »




Comments 

Add your comment

Comments are currently disabled
Robert Grønning
This should do the same thing with nmap:
$ nmap -sP 192.168.1.1-10
Posted 2009-04-01 10:03:19
i thought fping was a more convenient way to do this.
Posted 2009-04-01 12:53:56
users of BASH < 3 could use $(seq 1 100) instead of {1..100}...
lasting in

for IP in $(seq 1 100); do if ping 192.168.1.$IP -c 1 > /dev/null; then echo $IP alive; else echo $IP dead; fi; done
Posted 2009-04-01 13:24:39
Don Harper
True, one could use nmap or fping, but the code provided is very portable to any OS with a basic sh installed.
Posted 2009-04-01 14:33:53
Steve Shead
How about this? It seems a little complicated but it's a good one:

$ for i in `seq 1 255`; do ping -c 1 10.10.10.$i | tr \n ' ' | awk '/1 received/ {print $2}'; done
Posted 2009-04-01 16:34:56
darkglam
fping -g 192.168.1.1 192.168.1.10

Maybe need help of 1 pipe and egrep -v.
Posted 2009-04-02 15:44:04
Had to change the order of the command to put the flags in front of the $IP, and it helps to add a -t 1 to make dead addresses come back a little quicker.
Posted 2009-04-03 22:11:06

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit