Getting my public IP via API
Solution 1
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
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
In JSON format giving more details like the country and the user-agent:
https://www.trackip.net/ip?json
or only the IP
for pfsense (Check IP Services):
Solution 4
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`
Related videos on Youtube
Slava V
Updated on July 05, 2022Comments
-
Slava V over 1 year
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'surllib
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?
-
jfs about 10 years
-
ArtOfWarfare over 8 yearsDuck Duck Go has a public method for determining your IP address. I've detailed it more here, since this question is closed and I can't add an answer: stackoverflow.com/a/33743758/901641
-
Horcrux7 almost 8 yearsipify.org is an alternate service.
-
Laurent over 4 yearsI suggest trying Ipregistry: api.ipregistry.co/?key=tryout (disclaimer: I run the service).
-
Pierre Carrier about 2 yearsapi.ident.me welcomes robots :)
-
-
Slava V almost 14 yearsThat's awesome! Thanks a lot, esp. for dyndns one, that'll do!
-
mnagel over 10 yearsicanhazip.com returns the cleanest result imho
-
Ben Dowling over 10 yearsAlso ipinfo.io/ip
-
Navin over 10 yearsDoes not support HTTPS
-
Navin over 10 years@mnagel It also seems to be the only one that supports HTTPS. How ironic...
-
Ben Dowling about 10 yearsThe paid plans all have HTTPS support. See ipinfo.io/pricing
-
rodvlopes about 9 yearsI am moving from ifconfig.me to ipinfo.io due to slowness
-
Yoan Tournade over 7 yearsYou may check ipify.org, that have a clear API and does support HTTPS.
-
Ryan H. over 7 yearsicanhazip.com is so far the only one I've encountered that is both IPv6 capable and ATS (TLSv1.2 & PFS) compliant. Now, if I can just find an API set like ipv6-test.com/api that allows forcing IPv4 or IPv6 and is ATS compliant, that would be terrific!
-
نرم افزار حضور و غیاب over 6 yearsip-api.com/json is fastest way and it has best response time. 150 requests/minute
-
rustyx about 4 yearsNice. Also supports IPv6.
-
rustyx about 4 yearsNo IPv6 support...
-
rustyx about 4 yearsNo IPv6 support...
-
rustyx about 4 yearsNice, icanhazip.com supports IPv6.
-
Ben Dowling about 4 yearsIt supports IPv6 via v6.ipinfo.io
-
Raman about 4 yearsLooks like https is now supported, no paid plan required.
-
Ayan Sengupta over 3 yearsSupports https too. Upvoted.
-
Pierre Carrier about 2 years@RyanH. how about api.ident.me? Provides IPv4 vs IPv6, supports HTTPS and TLSv1.2 (works in nscurl). Disclaimer: I'm the author.