0

Possible Duplicate:
Finding the Public IP address in a shell script

For use in scripting, it would be handy to be able to do this:

IP=`....something ....`
echo ...$IP... >> configfile

I'm looking for the IP address as seen by the web, in this instance. Ubuntu, if it makes a difference. Happy to install a package or two.

Steve Bennett
  • 5,539
  • 12
  • 45
  • 57

1 Answers1

5
IP=`curl ifconfig.me`

[stephan@nemesis] ~ $ curl ifconfig.me
173.13.169.18

Voila. :)

(Edit Sept 2020)

I usually use icanhazip.com now. You may need to chop the newline, though:

curl -s icanhazip.com | tr -d '\n'

Stephan
  • 999
  • 7
  • 11
  • I'd suggest, ifconfig.me returns (to curl) only the IP address without any header or body tags. – Stephan Feb 05 '13 at 02:22