Skip to content

Instantly share code, notes, and snippets.

@earvinpiamonte
Created July 24, 2025 14:47
Show Gist options
  • Save earvinpiamonte/ae718316e8469bb9d03c550e574efbd5 to your computer and use it in GitHub Desktop.
Save earvinpiamonte/ae718316e8469bb9d03c550e574efbd5 to your computer and use it in GitHub Desktop.
ip() {
case "$1" in
public)
echo "$(curl -s https://api.ipify.org | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')"
;;
internal)
ipconfig getifaddr $(route get default 2>/dev/null | awk '/interface: / {print $2}')
;;
private)
ifconfig | awk '/^(utun|ppp)/ {iface=$1} iface && $1 == "inet" && $2 ~ /^10\./ {print $2; exit}'
;;
*)
echo "Usage: ip [public|internal|private]"
return 1
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment