Pingcheck
In my previous posts I have discussed other scripts to monitor or work with DNS. This pingcheck script is used to find used or unused IP addresses in the network, or to populate an arp table for a subnet. You can download the following code here as a normal shell script or as a .tar file.
This script also uses jot, one of the first scripts I posted from my script library.
#!/bin/bash
# 2005-06-06 Jud Bishop
# Released under GPLv2.
# pingcheck -- Finds open ip addresses or inversely active ip addresses in a range.
# Output includes activity as well as DNS resolution.
if [ -z "$1" ]
then
echo "Usage:"
echo " pingcheck 190 254 192.168.1"
echo " 190 is the starting ip address"
echo " 254 is the last ip address"
echo " 192.168.1 is the subnet"
echo "Example:"
echo " pingcheck 190 254 192.168.1 "
else
for I in `jot -s $1 -e $2`
do
NAME=`nslookup $3.$I | grep = |cut -d = -f 2`
# These two lines are the same, just different ways to clean up the output.
#ping -c 1 -w 1 $3.$I 2>/dev/null 1>/dev/null
ping -c 1 -w 1 $3.$I >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo $3.$I exists $NAME;
else
echo $3.$I does not exist $NAME;
fi
done
fi
# 2005-06-06 Jud Bishop
# Released under GPLv2.
# pingcheck -- Finds open ip addresses or inversely active ip addresses in a range.
# Output includes activity as well as DNS resolution.
if [ -z "$1" ]
then
echo "Usage:"
echo " pingcheck 190 254 192.168.1"
echo " 190 is the starting ip address"
echo " 254 is the last ip address"
echo " 192.168.1 is the subnet"
echo "Example:"
echo " pingcheck 190 254 192.168.1 "
else
for I in `jot -s $1 -e $2`
do
NAME=`nslookup $3.$I | grep = |cut -d = -f 2`
# These two lines are the same, just different ways to clean up the output.
#ping -c 1 -w 1 $3.$I 2>/dev/null 1>/dev/null
ping -c 1 -w 1 $3.$I >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo $3.$I exists $NAME;
else
echo $3.$I does not exist $NAME;
fi
done
fi
Categories: Code