Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a command line way to show the outward-facing IP address for my machine?

share|improve this question

migrated from stackoverflow.com Nov 3 '09 at 15:30

This question came from our site for professional and enthusiast programmers.

3 Answers 3

ifconfig.me has some great cmd line options.

This returns your ip

curl ifconfig.me/ip

This returns a large chunk of info

curl ifconfig.me/all
share|improve this answer

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:

wget -q -O - checkip.dyndns.org

*Network address translation.

**This is only a hand-wavey description of how NAT works.

share|improve this answer
    
Adding a little sed to parse it: wget -q -O - checkip.dyndns.org | sed 's/.*: (.*)<\/body.*$/\1/' –  jon077 Apr 14 '11 at 3:31

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.

curl http://checkip.dyndns.org/ 2> /dev/null | ruby -pe '$_=$_.scan(/\d+\.\d+\.\d+\.\d+/)'
share|improve this answer

protected by Synetech Nov 25 '13 at 20:41

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?