2009-08-20 12:21

To know the IP address you use to go out on the Internet, you can use a site like http://www.whatismyip.com

In text mode with no Web browser, it’s a bit more complicated. You can use the following command:

wget --user-agent="Mozilla/5.0" -O - http://www.whatismyip.com 2>/dev/null | grep -o "Your IP Address Is: [0-9.]*"

We have to simulate a real browser, or the site refuses us.

UPDATE 14/01/2010

To find your external IP address, an even more elegant way:

dig +short myip.opendns.com @resolver1.opendns.com

UPDATE 06/05/2010

The best way:

curl icanhazip.com

http://www.commandlinefu.com/commands/view/2966/return-external-ip

2009-08-20 12:21 · Tags: ,