I created the following script and what it basically does is ask for a server to query and then ping s it, it then echoes the average return time and then uses nmap to tell what ports are open on that host.
The only problem is it works on my home computer but not my work one
SCRIPT:
#! /bin/bash
# The temporary files used by the script
tmp=/tmp/nmapped.$$
ping_temp=/tmp/ping.$$
sharefile=/tmp/sharefile.$$
DOIT=Y
while [ $DOIT = "Y" ]
do {
# Asks you what you want to ping and then puts it out as the variable
if [ $LOGNAME != "root" ] ; then
echo ""
tput bold
echo "WARNING! You must be logged in as 'root' for this script to run properly!"
tput sgr0
else
echo ""
fi
echo ""
echo "-----------------------"
tput bold
echo "(NOTE: THE PID FOR THIS APPLICATION IS $$)"
tput sgr0
echo ""
tput bold
echo -n "What server do you want to test? "
tput sgr0
read server
echo ""
echo "-----------------------"
echo "Pinging $server....."
echo ""
# Pings the server that was entered as the server variable
ping -c 4 $server 2>&1 | grep avg | awk '{print $4}' | cut -d'/' -f2 > $ping_temp
# Checks the server status and then advises of it's status
if [ -s $ping_temp ] ; then
echo "$server responds to ping"
else
echo "$server doesn't appear to be up" ; exit
fi
echo ""
echo "Average reply time - `cat $ping_temp`ms"
echo ""
echo "-----------------------"
echo ""
# Checks server and gets port info
tput bold
echo -n "Do you want detailed information for this server? (y/n) "
tput sgr0
read detail
if [ $detail == "n" -o $detail == "N" ] ; then
exec nmap $server | grep open > $tmp
else
exec nmap -A -T4 -F $server | grep open > $tmp
fi
count=`wc -l $tmp | awk '{print $1}'`
echo "There are $count ports open on \"$server\""
echo ""
echo "-----------------------"
echo ""
# Prints lists of open ports on server
cat $tmp
rm $tmp
rm $ping_temp
echo ""
echo "-----------------------"
echo ""
}
DOIT=N
tput bold
echo -n "Do you want to ping another host? "
tput sgr0
read DOIT
DOIT=`echo $DOIT | tr '[a-z]' '[A-Z]'`
done