Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added in various IP addresses #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions check-my-net
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
#!/usr/bin/env bash

ghome=google.com
gdns=8.8.8.8
gifc=$(ip route | awk '/default/ { print $5 }')
gway=$(ip route | awk '/default/ { print $3 }')
# DNS is limited to 3 entries. Get the last 1 of those 3
gdns=$(cat /etc/resolv.conf | grep -i '^nameserver' | head -n3 | cut -d ' ' -f2 | tail -n1)

if ping -q -c 5 "$ghome" >/dev/null 2>&1
# look for nameserver in resolv.conf | strip away front text | get the third item in the list
ginterface=$(ip route | awk '/default/ {print $5}')
gateway=$(ip route | awk '/default/ {print $3}')
gipaddr=$(hostname -I | awk '{print $1}')

if ping -q -c 4 "$ghome" >/dev/null 2>&1
then
# can ping google, dns is working
tput sgr0
echo ""
echo -e '\E[1;32m'"You are connected to internet via interface \"$gifc\""
echo ""
echo -e '\E[1;32m'"You are connected to the internet\e[0m"
echo "Your IP: $gipaddr"
echo "Interface: $ginterface"
echo "Gateway: $gateway"
gextipaddr=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com)
echo "External IP: ${gextipaddr//\"}" # get rid of quote marks
echo "DNS server: $gdns"
tput sgr0
exit 0
else
if ping -q -c 5 "$gdns" >/dev/null 2>&1
# cant ping google, dns not working?
if ping -q -c 4 "$gdns" >/dev/null 2>&1
then
# can ping dns, cant ping google
tput sgr0
echo ""
echo -e '\E[1;36m'"Your DNS server(s) does not seem to be responding"
echo -e '\E[1;36m'"\"/etc/resolv.conf\" file might be of interest to you"
echo ""
echo -e '\E[1;36m'"Your DNS server does not seem to be responding. \"/etc/resolv.conf\" file might be of interest to you\e[0m"
echo "Your IP: $gipaddr"
echo "Interface: $ginterface"
echo "Gateway: $gateway"
echo "DNS server: $gdns"
echo "External IP: Unknown"
tput sgr0
exit 1
else
if ping -q -c 5 "$gway" >/dev/null 2>&1
# cant ping dns
if ping -q -c 4 "$gway" >/dev/null 2>&1
then
# can ping gateway, but not dns
tput sgr0
echo ""
echo -e '\E[1;33m'"Problem seems to be with the ISP. Contact the ISP"
echo ""
echo -e '\E[1;33m'"Problem seems to be with the ISP. Contact the ISP\e[0m"
echo "Your IP: $gipaddr"
echo "Interface: $ginterface"
echo "Gateway: $gateway"
echo "DNS server: Unknown"
echo "External IP: Unknown"
tput sgr0
exit 1
else
# cant ping gateway or dns
tput sgr0
echo ""
echo -e '\E[1;31m'"Can't connect to either your router or your modem"
echo -e '\E[1;31m'"Make sure the PC's network is properly configured"
echo -e '\E[1;31m'"Also make sure the router or modem is switched on"
echo -e '\E[1;31m'"Do check that network cable is correctly attached"
echo -e '\E[1;31m'"In case of wireless router check the signal level"
echo ""
echo -e '\E[1;31m'"Can't connect to either your router or your modem. Make sure the PC's network is properly configured. Also make sure the router or modem is switched on. Do check that network cable is correctly attached. In case of wireless router check the signal level\e[0m"
echo "Your IP: $gipaddr"
echo "Interface: $ginterface"
echo "Gateway: Unknown"
echo "DNS server: Unknown"
echo "External IP: Unknown"
tput sgr0
exit 1
fi
Expand Down