fixed network module for macOS

This commit is contained in:
Léana 江 2022-12-24 04:17:04 +01:00
parent 1c2cee4cf5
commit 99a6fc0770

View file

@ -3286,6 +3286,16 @@ get_network() {
fi fi
done < <(find /sys/class/net/ -type l) 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 }'|cut -d " " -f3-)
if [[ $ActiveNetworkName == "Wi-Fi" ]]; then
LinkSpeed="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/maxRate/{ print }' | xargs | cut -d " " -f2)Mbps"
else
LinkSpeed="$(ifconfig $ActiveNetwork | grep 'media:' | gsed -E "s/.*\((.*)\).*/\1/gm")"
fi
network="$ActiveNetwork: $ActiveNetworkName@$LinkSpeed"
;;
esac esac
while IFS=' ' read -r n i; do while IFS=' ' read -r n i; do
if [ -n "$i" ]; then if [ -n "$i" ]; then