Ping random IP to see if there's connection


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. One that just checks a random IP on the internet to see if we have internet access:
  2. Code:
  3.  
  4. shopt -s extglob
  5. GW=216.239.32.10
  6. IFS=''
  7. PING=`ping -c1 -n -t5 -o $GW`
  8. RC=$?
  9. if [ $RC -eq 2 ]; then
  10. echo "Internet ($GW) no reply"
  11. exit 1
  12. fi
  13. RT=$( echo $PING | head -n2 | tail -n1 | awk -F= '{print $4}' )
  14. echo "Internet ($GW) $RT"
  15. exit $RC

URL: http://projects.tynsoe.org/phpBB2/viewtopic.php?p=745

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.