One-liner: How to scan a network for up & down hosts

Another network scanner.

For example, you want to find possible free IP-addresses in the – range:

for i in {1..10}; do (ip="10.0.10.$i"; up=`ping -n -q -W3 -c1 $ip | fgrep transmitted | sed -e 's/.*100%.*/down/' -e 's/.*0%.*/up/'`;name=`host $ip | awk '!/NXDOMAIN/{print $NF}'`; echo $ip $up $name)  2>/dev/null & done | sort -n -t. -k4

Result: down down up host1. down down myhost2.internal.domain. up nas3. down laptop. down up switch2. down printer.

See also: One-liner: how to do a ping sweep in bash

Leave a Reply

Your email address will not be published. Required fields are marked *