Skip to content

Instantly share code, notes, and snippets.

@MarcelFox
Last active February 16, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcelFox/ccd5c0313984ae98a3d435a3a6ed5e79 to your computer and use it in GitHub Desktop.
Save MarcelFox/ccd5c0313984ae98a3d435a3a6ed5e79 to your computer and use it in GitHub Desktop.
Check connection and IPs of a host.
#!/bin/bash
status_conn=$(wget -q --spider http://google.com && echo 0 || echo 1)
if [ $status_conn -eq 1 ]
then
printf "\n \e[36m Your Internet is pretty much dead!\n Check your networks...\e[0m\n\n";
elif [ $status_conn -eq 0 ]
then
external=$(dig +short myip.opendns.com @resolver1.opendns.com);
locally=$(ip addr | grep -v inet6 | grep inet | awk '{print $2}'|cut -d"/" -f1 | tail -n1 | head -n2);
printf "\n \e[4mExternal\e[0m IP:\t\e[1m\e[32m$external\e[0m\n \e[4mLocal\e[0m IP:\t$locally\n\n";
fi
@MarcelFox
Copy link
Author

MarcelFox commented Dec 10, 2017

You can run it directly using curl:

bash <(GET https://gist.githubusercontent.com/MarcelFox/ccd5c0313984ae98a3d435a3a6ed5e79/raw/97b7af7945b12871dcbba90608534311eb50ed28/check_conn.sh)

You must install the proper 'dnsutils' package on your distribution in order to run dig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment