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

link|improve this question
feedback

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

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

10 Answers

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.

link|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
feedback

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+/)'
link|improve this answer
feedback
links http://www.whatismyip.com/

The only conclusive way to show your IP is from the outside in.

link|improve this answer
or ipchicken, yeah, some sites will display it for information or security purposes. just bugs me that there is no internal way to find out that information. – zim Nov 3 '09 at 15:13
1  
there's no internal way because your machine has no way of knowing what's between it and the internet. – Chris AtLee Nov 3 '09 at 15:19
feedback

This is not going to be the best answer for this problem. You can parse the output of your nat router's HTML and find the IP address from that. What environment are you in, windows, linux, osx?

link|improve this answer
+1 just to try and invalidate your modesty (honesty?) in the first sentence. :-P – Andrzej Doyle Nov 3 '09 at 15:14
Eh, thanks I think :). – Mark Tomlin Nov 3 '09 at 15:47
feedback
wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1

This will show just your external ip. I found this at http://bbs.archlinux.org/viewtopic.php?id=53709

link|improve this answer
feedback

nslookup on the fqn might work

link|improve this answer
feedback

That of course depends on your operating system, and your local network topology.

If you're behind a NAT and/or firewall, I think the answer is "no".

Otherwise, try ifconfig in Linux or ipconfig in Windows.

link|improve this answer
feedback

echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | nc whatismyip.com 80 | tail -n 1

link|improve this answer
feedback

If You just want to manually check ip I think You can try traceroute

link|improve this answer
feedback

Your Answer

 
or
required, but never shown