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
This question came from our site for professional and enthusiast programmers.
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.
ifconfig.me has some great cmd line options.
This returns your ip
This returns a large chunk of info
protected by Synetech Nov 25 '13 at 20:41
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?