[PR] #56 from leana8959: Fix macOS network detection

Fix network module on macOS
This commit is contained in:
Hykilpikonna 2022-12-24 02:38:20 -05:00 committed by GitHub
commit 14c7963d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3286,6 +3286,16 @@ get_network() {
fi
done < <(find /sys/class/net/ -type l)
;;
"Mac OS X"|"macOS")
ActiveNetwork=$(route get default | grep interface | awk '{print $2}')
ActiveNetworkName=$(networksetup -listallhardwareports | grep -B 1 "$ActiveNetwork" | awk '/Hardware Port/{print}'| awk '{print $3}')
if [[ $ActiveNetworkName == "Wi-Fi" ]]; then
LinkSpeed="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/maxRate/{print}' | awk '{print $2}' )Mbps"
else
LinkSpeed="$(ifconfig "$ActiveNetwork" | awk '/media/{print}' | sed -E "s/.*\((.*)\).*/\1/")"
fi
network="$ActiveNetwork: $ActiveNetworkName@$LinkSpeed"
;;
esac
while IFS=' ' read -r n i; do
if [ -n "$i" ]; then