A walkthrough for building a cross-platform `myip` shell script that retrieves both local and public IP addresses from the command line. For the public IP, it uses `curl` against ifconfig.me with flags for reliability. For the local IP on Linux, it uses `ip route get 1.1.1.1` with a Perl regex to extract the source address without making an actual external network call — verified using `strace`. The macOS equivalent uses `route -n get 1.1.1.1` piped through `awk` and `ipconfig getifaddr`. The final script supports `-l` and `-p` flags to print and copy either address to the clipboard.

10m read timeFrom nickjanetakis.com
Post cover image
Table of contents
# Public IP Address# Local IP Address# Dedicated Script# Demo Video

Sort: