Created
July 25, 2018 15:50
-
-
Save rmanly/a0ca0a7e35f8aad33049460b2434120c to your computer and use it in GitHub Desktop.
Prints the first IP address encountered based on network service order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
devices=($(networksetup -listnetworkserviceorder | awk -F': ' '/Port/{ gsub(/\)$/,""); print $3 }')) | |
for iface in "${devices[@]}"; do | |
if ! ipconfig getifaddr "$iface"; then | |
continue | |
else | |
exit 0 | |
fi | |
done | |
echo "None" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment