Finding external IP using external services
The easiest way is to use an external service via a commandline browser or download tool. Sincewget
is available by default in Ubuntu, we can use that.To find your ip, use-
wget -qO- http://ipecho.net/plain ; echo
You could also use
lynx
(browser) or curl
in place of wget
with minor variations to the above command, to find your external ip.Using
curl
to find the ip:
curl ipecho.net/plain
For a better formatted output use:
curl ipecho.net/plain ; echo
A faster(arguably the fastest)
method using dig with OpenDNS as resolver:
The other answers here all go over HTTP to a remote server. Some of them require parsing of the output, or rely on the User-Agent header to make the server respond in plain text. They also change quite frequently (go down, change their name, put up ads, might change output format etc.).
Using dig with OpenDNS as resolver:
- The DNS response protocol is standardised (the format will stay compatible).
- Historically DNS services (OpenDNS, Google Public DNS, ..) tend to survive much longer and are more stable, scalable and generally looked after than whatever new hip whatismyip.com HTTP service is hot today.
- (for those geeks that care about micro-optimisation), this method should be inherently faster (be it only by a few micro seconds).
$ dig +short myip.opendns.com @resolver1.opendns.com
111.222.333.444
Finding external IP
without relying on external services
- If you know your network interface name
ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
In the above, replace
with the name of your actual interface, e.g:
eth0
, eth1
, pp0
, etc...Example Usage:
mycomp@geek:~$ ifconfig ppp0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
111.222.333.444
- If you don't know your network interface name
ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 }
else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'
Example Usage:
mycomp@geek:~$ ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 }
else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'
lo: 127.0.0.1
ppp0: 111.222.333.444
No comments:
Post a Comment