Is there a command line way to show the outward-facing IP address for my machine?
migrated from stackoverflow.com Nov 3 '09 at 15:30
You could put together a script which calls whatismyip.com or similar and returns the interesting part (although such websites might not like you doing that). Generally, you're going to have to ask someone else (other computer) what your IP is, since your computer does not know. You could also possibly ask your router, but the parsing will probably be harder.
Your computer does not know it's external IP address because the router is using NAT*. A packet leaving your computer has from:[your internal IP], but the router mangles that into from:[Your router's external IP] and sends it onto the internet. The router then unmangles (or remangles) the to: field on the returned packets and forwards them to your computer.**
You can get a nearly-clean output from:
*Network address translation.
**This is only a hand-wavey description of how NAT works.
You can get it from various websites out there in the world, like checkip.dyndns.org. Once you have a site that tells you your IP address, it shouldn't be too hard to use curl to fetch the page and awk to parse it.