getting external IP from unix command line

walla

Senior member
Jun 2, 2001
987
0
0
Is it possible to get the external IP address from some common unix command?

ifconfig -a will give me the local IP address...but thats not what I want.

I know that some websites can tell you the external IP. Thats not the solution I want. Ideally, I would like to be able to grep the output of some unix command and pipe it to an application that will monitor it.

One solution I can think of is use wget to get the html source of one of these webpages but that doesn't seem like the best solution.

Any other ideas?
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
The wget method is probably the best (or lynx -dump). I can't think of anything else off hand.
 

walla

Senior member
Jun 2, 2001
987
0
0
i have found the following will work...

wget -O - http://www.whatismyip.com/ | grep 'Your IP is' | sed -e 's/.* is //' -e 's/ .*//'

Of course...if the site goes down or changes structure, my solution breaks. Thats what I want to avoid.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Of course...if the site goes down or changes structure, my solution breaks. Thats what I want to avoid.

The only way to avoid that would be to manage the external site yourself. You could always write a script using ssh (or telnet if you have a crappy router) to log into the router and get the IP from it's external interface.
 

Sunner

Elite Member
Oct 9, 1999
11,641
0
76
Originally posted by: Nothinman
Of course...if the site goes down or changes structure, my solution breaks. Thats what I want to avoid.

The only way to avoid that would be to manage the external site yourself. You could always write a script using ssh (or telnet if you have a crappy router) to log into the router and get the IP from it's external interface.

Or you could just wget www.google.com/index.html, the chances of Google diving should be far smaller than your router taking a crap.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Or you could just wget www.google.com/index.html, the chances of Google diving should be far smaller than your router taking a crap.

Yes but with the ssh/telnet solution you could check for connectivity and also do something about it if you wanted to, like reboot the router or something. It really depends on how far you want to take this.