Getting my public IP via API

You can get your IP, and a whole bunch of other information, from my service http://ipinfo.io:

$ curl ipinfo.io
{
  "ip": "67.188.232.131",
  "hostname": "c-67-188-232-131.hsd1.ca.comcast.net",
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.385999999999996,-122.0838",
  "org": "AS7922 Comcast Cable Communications, Inc.",
  "phone": 650
}

If you want just the IP:

$ curl ipinfo.io/ip
67.188.232.131

That also works for other fields, eg:

$ curl ipinfo.io/org
AS7922 Comcast Cable Communications, Inc.

More details available at http://ipinfo.io/developers


While not from big companies, all of these should work:

curl icanhazip.com
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
host -t a dartsclink.com | sed 's/.*has address //'
curl curlmyip.com
curl ifconfig.me # this has a lot of different alternatives too, such as ifconfig.me/host

Source

  • http://www.commandlinefu.com/commands/view/2966/return-external-ip#comment

Tags:

Ip

Api