Getting my public IP via API

ApiIp

Api Problem Overview


Is there a public API from some big company to get my public ip from within a program?

I've found http://ip-address.domaintools.com/myip.xml, which is exactly what I want, but unfortunately it blocks Python's urllib as well as many other http libraries, unless you spoof user-agent (anything doing that can't be called an API at all).

The problem is that I need this data for some potentially open source library, so we have to play by the rules. I also know that I can just do smth like print $_SERVER[REMOTE_ADDR], but I don't want to server traffic to everyone using my library.

So, is there something like the URL above, but real API, that allows robots?

Api Solutions


Solution 1 - Api

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

Solution 2 - 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

Solution 3 - Api

In JSON format giving more details like the country and the user-agent:

https://www.trackip.net/ip?json

or only the IP

https://www.trackip.net/ip

for pfsense (Check IP Services):

http://trackip.net/pfsense

Solution 4 - Api

I use this one, easy to remember and it's shorter than others:

$ curl ifconfig.me

PROTIP: Remember that if you use curl in shell scripts you have to use -s option, otherwise it prints the download progress table.

$ echo `curl -s ifconfig.me`

Solution 5 - Api

Yes you may try out with whoisthisip.com

http://whoisthisip.com/HRAS/ Register to whoisthisip.com to get a website's IP address information such as city location, country location and domain name.

Once signed in, you will be given a reference code and a url to view and get the information of IP address for the website you registered.

Solution 6 - Api

you can use web service API's which do this work like:

see example of service: http://ip-api.com and usage: http://whatmyip.info

good luck!!!

Solution 7 - Api

Solution 8 - Api

If you cannot install curl in your system wget variant would be:

wget -qO- curlmyip.com

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSlava VView Question on Stackoverflow
Solution 1 - ApiJamie WongView Answer on Stackoverflow
Solution 2 - ApiBen DowlingView Answer on Stackoverflow
Solution 3 - ApinbariView Answer on Stackoverflow
Solution 4 - ApisscarduzioView Answer on Stackoverflow
Solution 5 - ApiAdam BijuView Answer on Stackoverflow
Solution 6 - Apiuser3463375View Answer on Stackoverflow
Solution 7 - ApirkhanView Answer on Stackoverflow
Solution 8 - ApimimoraleaView Answer on Stackoverflow