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

misc updates #10

Merged
merged 1 commit into from
Aug 27, 2022
Merged
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
20 changes: 10 additions & 10 deletions wireless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
# Set toggle for found IP on an interface to FALSE to start
IPFOUND=
# Determine Current OS Version
OSVERSION=`uname -a | awk '{print $3}' | awk 'BEGIN {FS = "."} ; {print $1}'`
OSVERSION=$(uname -a | awk '{print $3}' | awk 'BEGIN {FS = "."} ; {print $1}')
# Get list of possible wired ethernet interfaces
INTERFACES=`networksetup -listnetworkserviceorder | grep "Hardware Port" | grep "Ethernet\|LAN\|Thunderbolt\|AX88179A" | awk -F ": " '{print $3}' | sed 's/)//g'`
INTERFACES=$(networksetup -listnetworkserviceorder | grep "Hardware Port" | grep "Ethernet\|LAN\|Thunderbolt\|AX88179A" | awk -F ": " '{print $3}' | sed 's/)//g')
# Get list of Wireless Interfaces
WIFIINTERFACES=`networksetup -listallhardwareports | tr '\n' ' ' | sed -e 's/Hardware Port:/\'$'\n/g' | grep Wi-Fi | awk '{print $3}'`
WIFIINTERFACES=$(networksetup -listallhardwareports | tr '\n' ' ' | sed -e 's/Hardware Port:/\'$'\n/g' | grep Wi-Fi | awk '{print $3}')

# Look for an IP on all Ethernet interfaces. If found set variable IPFOUND to true.
for INTERFACE in $INTERFACES
do
# Get Wired LAN IP (If there is one other then the loopback and the self assigned.)
IPCHECK=`ifconfig $INTERFACE | egrep 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v '127.0.0.1|169.254.' | awk '{print $2}'`
if [ $IPCHECK ]; then
IPCHECK=$(ifconfig "$INTERFACE" | grep -E 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v '127.0.0.1|169.254.' | awk '{print $2}')
if [ "$IPCHECK" ]; then
IPFOUND=true
fi
done
Expand All @@ -33,21 +33,21 @@ if [ "$OSVERSION" == "9" ]; then
# For OSX 10.6 (#10) Snow Leopard
elif [ "$OSVERSION" == "10" ]; then
if [ $IPFOUND ]; then
/usr/sbin/networksetup -setairportpower $WIFIINTERFACES off || exit 1
/usr/sbin/networksetup -setairportpower "$WIFIINTERFACES" off || exit 1
logger "wireless.sh: turning off wireless card ($WIFIINTERFACES) because an IP was found on a wired card."
else
/usr/sbin/networksetup -setairportpower $WIFIINTERFACES on || exit 1
/usr/sbin/networksetup -setairportpower "$WIFIINTERFACES" on || exit 1
logger "wireless.sh: turning on wireless card ($WIFIINTERFACES) because NO IP was found on a wired card."
fi

# For OSX 10.7 (#11) Lion and OSX 10.8 (#12) Mountain Lion and 10.9 (#13) Mavericks, Yosemite (#14), El Capitan (#15), Sierra (#16), High Sierra (#17), Mojave (#18), Catalina (#19), Big Sur (#20), Monterey (#21)
elif [ "$OSVERSION" == "11" -o "$OSVERSION" == "12" -o "$OSVERSION" == "13" -o "$OSVERSION" == "14" -o "$OSVERSION" == "15" -o "$OSVERSION" == "16" -o "$OSVERSION" == "17" -o "$OSVERSION" == "18" -o "$OSVERSION" == "19" -o "$OSVERSION" == "20" -o "$OSVERSION" == "21" ]; then
elif [ "$OSVERSION" == "11" ] || [ "$OSVERSION" == "12" ] || [ "$OSVERSION" == "13" ] || [ "$OSVERSION" == "14" ] || [ "$OSVERSION" == "15" ] || [ "$OSVERSION" == "16" ] || [ "$OSVERSION" == "17" ] || [ "$OSVERSION" == "18" ] || [ "$OSVERSION" == "19" ] || [ "$OSVERSION" == "20" ] || [ "$OSVERSION" == "21" ]; then
if [ $IPFOUND ]; then
/usr/sbin/networksetup -setairportpower $WIFIINTERFACES off || exit 1
/usr/sbin/networksetup -setairportpower "$WIFIINTERFACES" off || exit 1
echo "Turning OFF wireless on card $WIFIINTERFACES."
logger "wireless.sh: turning off wireless card ($WIFIINTERFACES) because an IP was found on a wired card."
else
/usr/sbin/networksetup -setairportpower $WIFIINTERFACES on || exit 1
/usr/sbin/networksetup -setairportpower "$WIFIINTERFACES" on || exit 1
echo "Turning ON wireless on card $WIFIINTERFACES."
logger "wireless.sh: turning on wireless card ($WIFIINTERFACES) because NO IP was found on a wired card."
fi
Expand Down