Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from 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 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 -

*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 - | sed 's/.*: (.*)<\/body.*$/\1/' – jon077 Apr 14 '11 at 3:31

You can get it from various websites out there in the world, like 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 2> /dev/null | ruby -pe '$_=$_.scan(/\d+\.\d+\.\d+\.\d+/)'
share|improve this answer has some great cmd line options.

This returns your ip


This returns a large chunk of info

share|improve this answer

You must log in to answer this question.

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?