改善
Kaizen  · Today I Learned by Ville Säävuori

Finding Your IP Addres(ses) Via macOS Command Line

I needed a programmatic way to figure out my local and public IP address for a WebRTC app. I’m also using Tailscale so in case I was connected to it I want to use the Tailscale IP instead.

These commands worked for me on macOS 12.6 Monterey:

Local IP

ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'

Public IP

dig +short myip.opendns.com @resolver1.opendns.com

Tailscale IP

tailscale ip --1

(Use tailscale status to determine if you’re connected or not.)