2020-04-29 15:36:11 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-10-17 00:38:29 +02:00
|
|
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
|
|
|
export LC_ALL=en_US.UTF-8
|
2020-03-15 22:18:06 +01:00
|
|
|
|
2020-04-29 15:36:11 +02:00
|
|
|
HOSTS="google.com github.com example.com"
|
2020-03-15 22:18:06 +01:00
|
|
|
|
|
|
|
get_ssid()
|
|
|
|
{
|
2021-07-06 10:22:36 +02:00
|
|
|
# Check OS
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
|
|
|
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
|
|
|
|
if [ -n "$SSID" ]; then
|
|
|
|
printf '%s' "$SSID"
|
|
|
|
else
|
|
|
|
echo 'Ethernet'
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
Darwin)
|
|
|
|
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 | sed 's/ ^*//g' &> /dev/null; then
|
|
|
|
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)" | sed 's/ ^*//g'
|
|
|
|
else
|
|
|
|
echo 'Ethernet'
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
|
|
# leaving empty - TODO - windows compatability
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2020-04-07 21:53:34 +02:00
|
|
|
|
2020-03-15 22:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2021-07-06 10:22:36 +02:00
|
|
|
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"
|
2020-03-15 22:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#run main driver function
|
|
|
|
main
|