I am looking for a "reliable" way to find out what network is the computer using.
I think I have the WiFi part working.
check_wifi_status() {
local wifi_interface=$(networksetup -listallhardwareports | grep -A 1 Wi-Fi | awk '/Device:/ {print $2}')
if [ -n "$wifi_interface" ]; then
local wifi_status=$(networksetup -getairportpower "$wifi_interface" | awk '{print $4}')
if [ "$wifi_status" = "On" ]; then
local ssid=$(networksetup -getairportnetwork "$wifi_interface" | awk -F': ' '{print $2}')
echo "WiFi status ($wifi_interface): On"
echo "Connected to network ($wifi_interface): $ssid"
else
echo "WiFi status ($wifi_interface): Off"
fi
else
echo "WiFi interface not found"
fi
}
With ethernet, users can be using different brand name docking station and also other network adapter/card may not be an actual working ethernet adapter. Some could be for ZTNA or Netskope or some other service using an adapter.
I am looking for help with identifying if computer is connected to Ethernet or not (regardless of adapter/dock brand). Also looking for an active one only. Bonus if we can also tell which one is the primary one.
Thanks all!