General Connectivity Check for Internet and Specified Subnets
Jump to navigation
Jump to search
#!/bin/bash clear cat << EOF > /tmp/iplist <User Friendly Name> <IP in remote subnet to be tested against> EOF echo "----Checking Internet----" ping -c1 -W 1 8.8.8.8 &> /dev/null A=$? if [ $A = 0 ]; then traceroute -n -m 3 8.8.8.8 > /tmp/trace sed -i '/traceroute/d' /tmp/trace sed -i '/<name of script>/d' /tmp/trace sed -i '/10.*/d' /tmp/trace sed -i '/192.168.*/d' /tmp/trace hop=$(cat /tmp/trace | awk '{print $2}') rm -f /tmp/trace echo "Google = $(tput setaf 2)UP$(tput sgr 0) Tracepath : $(tput setab 7)$(tput setaf 0)$hop$(tput sgr 0)" unset hop elif [ $A = 1 ]; then echo "Google = $(tput setaf 1)DOWN$(tput sgr 0)" fi echo "----Checking Subnets----" while read line do name=$(echo $line | awk '{print $1}') ip=$(echo $line | awk '{print $2}') ping -c2 -W 1 $ip &> /dev/null A=$? if [ $A = 0 ]; then echo "$name = $(tput setaf 2)UP$(tput sgr 0)" elif [ $A = 1 ]; then echo "$name = $(tput setaf 1)DOWN$(tput sgr 0)" fi done < /tmp/iplist rm -f /tmp/iplist