So we have a script which find the WIFI and Ethernet IP address and then determines which network interface to turn off. The current script uses this method:
ether=$(networksetup -listallnetworkservices | Grep -m1 'Ethernet')
wireless=$(networksetup -listallnetworkservices | Grep -m1 'Wi-Fi')
echo "Ethernet Name: $ether"
echo "Wireless Name: $wireless"
if [[ -n $wireless ]];
then
getipaddywifi=$(networksetup -getinfo "$wireless" | awk 'NR ==2' | awk '{print $3'})
echo "WIFI IP: $getipaddywifi"
fi
if [[ -n $ether ]];
then
getipaddyether=$(networksetup -getinfo "$ether" | awk 'NR ==2' | awk '{print $3'})
echo "ETHERNET IP: $getipaddyether"
fi
The problem is that some users are using fancy adapters and docks and it's reporting they have ethernet addresses when they actually don't. So I'd like to have it cycle through all the network services with Ethernet in the name, find ip any have an IP, and then put it in the $getipaddyether value. Any thoughts?