Merge pull request #20 from pbui/network-hosts

scripts/network.sh: use a list of hosts
This commit is contained in:
Dane Williams 2020-04-29 08:04:33 -07:00 committed by GitHub
commit be0f37e5d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,10 @@
#/usr/bin/env bash
#!/usr/bin/env bash
#author: Dane Williams
#script for gathering internet connectivity info
#script is called in dracula.tmux program
HOSTS="google.com github.com example.com"
get_ssid()
{
@ -11,9 +12,9 @@ get_ssid()
case $(uname -s) in
Linux)
if iw dev | grep ssid | cut -d ' ' -f 2 &> /dev/null; then
echo $(iw dev | grep ssid | cut -d ' ' -f 2)
echo "$(iw dev | grep ssid | cut -d ' ' -f 2)"
else
echo ' Ethernet'
echo 'Ethernet'
fi
;;
@ -21,7 +22,7 @@ get_ssid()
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 &> /dev/null; then
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)"
else
echo ' Ethernet'
echo 'Ethernet'
fi
;;
@ -37,11 +38,15 @@ get_ssid()
main()
{
if ping -q -c 1 -W 1 github.com &>/dev/null; then
echo "$(get_ssid)"
else
echo ' Offline'
network="Offline"
for host in $HOSTS; do
if ping -q -c 1 -W 1 $host &>/dev/null; then
network="$(get_ssid)"
break
fi
done
echo " $network"
}
#run main driver function