Get your public IP from the command line
[~] curl ifconfig.me
8.8.x.x
http://ifconfig.me checks for the curl useragent, and gives you only the data you're looking for. Nice of them.
They've got a bunch of other useful URLs, usable from the command line, including hostname (useful for Amazon Route53 CNAMEs, for instance), useragent, language, etc:
[~] curl ifconfig.me/host
some.long.hostname.tld
[~] curl ifconfig.me/ua
url/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
[~] curl ifconfig.me/lang
You can also get everything as JSON:
[~] curl ifconfig.me/all.json
"connection":"","ip_addr":"108.219.154.250","lang":"","remote_host":"some.long.hostname.tld","user_agent":"curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5","charset":"","port":"61888","via":"","forwarded":"","mime":"*/*","keep_alive":"","encoding":""}
There's a table of all the URLS at http://ifconfig.me, just scroll down past your info.
Inspired by @tonyseek's protip: Getting Local Machine IP Address in Shell.
Written by Sean Kilgore
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#