Useful IP scan script for a specific subnet


This script checks all  IPs on a  specific subnet with a “ping” command.  It can be useful to find out which  IP  used on a specific 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 [/shell]

How  to  run?

Subnet:192.168.197.0/24

[shell]#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:

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me