You may find out your IP using commands like
ifconfig, but if your computer is behind a firewall, that is not the IP that the world sees. Here’s a quick how-to to find out what your external IP is.
First, let’s create an alias: (link)
Next time when you need the public IP of your computer, just type
getip in the command line and hit enter.
The above command gets the IP from http://whatismyip.com/automation/n09230945.asp (just copy and paste this URL to your location bar and hit enter, and see what it does!). The “
-q” is to suppress verbose information (quiet mode) and “
-O -” causes the output to be written to STDOUT.
You may use dyndns.org too to find out the IP, but in this case you may need some trimming: substitute the text within the code above by the following:
wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1
A few words about various flags above:
The output of the first command (everything before the first pipe) is
<code><html><head><title>Current IP Check</title></head><body>Current IP Address: xxx.xxx.xx.xx</body></html>
(the actual IP address is masked by x).
-o /dev/null“ part redirects the STDERR of
/dev/null. The “
-d :” option in first “cut” tells it to use colon (:) to be used as the delimiter and “
-f 2” causes it to print second of the delimited fields. Similarly, the flags of the second “cut” cause it to use “<” as the delimiter for the piped output from the first “cut” and choose the first of the delimited fields.
UPDATE: Another one using
curl [link]. You may again change the quoted text within the alias above by the following:
curl --connect-timeout 3 http://www.whatismyip.org/