Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Last active April 24, 2026 14:14
Show Gist options
  • Select an option

  • Save dannguyen/dd88e501b09c76d9a4dd2b7e2bf69a34 to your computer and use it in GitHub Desktop.

Select an option

Save dannguyen/dd88e501b09c76d9a4dd2b7e2bf69a34 to your computer and use it in GitHub Desktop.
printing out your public IP address via a MacOS CLI command

How to print your Public IP address on MacOS command line

i.e. how to not have to go to whatsmyip-dot-com

Simply prints out the IP address:

dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g'

A solution that depends on akamai:

curl -s http://whatismyip.akamai.com/ \
   | grep -E '^(\d|\.)+$'             \
   | xargs -I{} sh -c 'echo "IP: {}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment