This script checks all IPs on a spesific subnet with “ping” command. It can be useful to find out which IP used on a spesific subnet.
Method 1:
#!/bin/ksh Subnet=$1 for i in `seq 1 255`; do if ping -c1 $Subnet.$i|grep -q 'Unreachable' >/dev/null 2>&1 then echo $Subnet.$i -- Unreachable else echo $Subnet.$i -- Reachable fi done
Method 2:
#!/bin/ksh Subnet=$1 for i in `seq 1 255`; do if ping -c1 $Subnet.$i|grep 'transmitted'|awk '{print $6}'|cut -d '%' -f 1,1|grep -q "100" >/dev/null 2>&1 then echo $Subnet.$i -- Unreachable else echo $Subnet.$i -- Reachable fi done
How to run?
Subnet:192.168.197.0/24
#ksh /tmp/xx 192.168.197 192.168.197.1 -- Unreachable 192.168.197.2 -- Unreachable 192.168.197.3 -- Unreachable 192.168.197.4 -- Unreachable 192.168.197.5 -- Unreachable 192.168.197.6 -- Unreachable 192.168.197.7 -- Unreachable 192.168.197.8 -- Unreachable 192.168.197.9 -- Unreachable 192.168.197.10 -- Reachable 192.168.197.11 -- Unreachable 192.168.197.12 -- Unreachable
Tagged In: