WizardKit/.linux_items/archlive/airootfs/usr/local/bin/hw-diags-network
2017-12-06 18:10:39 -08:00

73 lines
1.5 KiB
Bash

#!/bin/bash
#
## WK HW diagnostics - Network
function test_connection() {
cmd="a"
if [[ -e "/sys/class/net/$1" ]]; then
cmd="a show $1"
fi
if ip $cmd | grep -Eq '(10.[0-9]+|172.(1[6-9]|2[0-9]|3[0-1]).[0-9]+|192.168).[0-9]+.[0-9]+'; then
return 0
else
return 1
fi
}
CLEAR="\e[0m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
# Header
echo "WK HW Diagnostics - Network"
echo ""
# Start Wifi if necessary
echo "Initializing..."
connect-to-network >/dev/null 2>&1
# Check network connection
echo -n "Network connection: "
if test_connection; then
echo -e "${GREEN}OK${CLEAR}"
else
echo -e "${RED}No access${CLEAR}"
exit 1
fi
# Check IP addresses
for d in /sys/class/net/*; do
device="$(basename $d)"
if [ "$device" != "lo" ]; then
if test_connection $device; then
ip="$(ip a show $device | egrep 'inet [0-9]' | sed -r 's#.*inet (.*?/[0-9]+).*#\1#')"
echo "$device: $ip" | awk '{printf " %-16s %s\n", $1, $2}'
fi
fi
done
# Check internet connection
echo -n "Internet connection: "
if ping -c 2 -q 8.8.8.8 >/dev/null 2>&1; then
echo -e "${GREEN}OK${CLEAR}"
else
echo -e "${RED}No access${CLEAR}"
exit 1
fi
# Check DNS
echo -n "DNS Resolution: "
if ping -c 2 -q google.com >/dev/null 2>&1; then
echo -e "${GREEN}OK${CLEAR}"
else
echo -e "${RED}Unable to resolve google.com${CLEAR}"
exit 1
fi
# Check speed
echo "Speedtest:"
speedtest-cli --simple | awk '{printf " %-16s %6.2f %s\n", $1, $2, $3}'