Photo by Austin Neill

What Is the Best API for Geolocating an IP Address?

by Ahmad Awais

This post was first published at ↓
What Is the Best API for Geolocating an IP Address?

What Is the Best API for Geolocating an IP Address?

While working on a recent project for a client, I found myself in the need of a good and reasonably reliable Geolocation API to find out more about a user that visits your site.

So, I did a little research for currently available APIs and came up with somewhat an exhaustive list. That is what I plan to share today.

I would use a web service that can return JSON data. Below are all the free *active* IP lookup services I could find and the information they return. If you know of any more, then do add a comment below. If you own one, reach out to me through the contact form, I’d love to talk.

JUST A NOTE!
👨‍💻 I’m teaching thousands of devs how to become
VSCode Power Users

🌟 IPStack → (recommended)

Remember FreeGEOIP.net? Well, it is now called IPStack. It has much better offerings, good enough free package, and affordable premium packages.

IPStack offers so much more inside the API response that has made me not only use IPStack for personal use but I also recommend you to take a look:

  • ✅ Standard/Bulk/Requester lookups
  • 💵 Currency-related data (name, symbol)
  • 🌐 Connection-related data (Internet service provider)
  • 🕖 Timezone-related data (daylight saving, GMT Offset)
  • 📍 Comprehensive location-related data (languages, calling code)
  • Specify fields to only get the data you want and save bandwidth
  • 💂‍♂️ Security-related data (Info on proxy, crawler, tor, threat level/type)

Just use this link https://api.ipstack.com/check?access_key=YOUR_ACCESS_KEY with the language of your choice to get all the details for more details, read the documentation →

Returns:

Pros:

  • 10,000 API requests per month for free.
  • 100% uptime as reported by UpTimeRobot which is another signal of a good IP to GEO API service. API speed is pretty much unmatchable.
  • Extra data points: Location (languages, country flag SVG/emoji, calling code, also helps with GDPR by reporting is_eu as true/false), timezone (daylight saving, GMT Offset), currency (name, symbol), connection (ISP), and much more.
  • Security Module: Which can be used to assess risks and threats originating from certain IP addresses before any harm can be done to a website or web application. Info about proxy, crawler, tor, threat level/type — makes this service great at many levels.
  • SMB + Enterprise: IPStack is backed by a company named apilayer I already use their invoicing SaaS and a couple other API services. It’s also trusted by enterprise companies like Microsoft, Airbnb, Samsung, and more. They can support millions of request per day.

Limitations:

  • Requires an email address to get your API key

db-ip.com

//api.db-ip.com/addrinfo?api_key=<*your api key*>&addr=<*ip address*>

Returns:

{
"address": "119.152.180.314",
"country": "PK",
"stateprov": "Central Pakistan",
"city": "Pakistan"
}

Limitations:

- 2,500 requests per hour
- Doesn’t support JSONP callbacks
- Requires IP address parameter
- Requires an email address to get your API key

🌟 IPInfo → (recommended)

IPInfo is another major player in the IP information niche. Since 2013 they have built a customer base of over 100,000 including npm, CBS, Dell, Vodafone and serve 12 Billion IP API requests per month. The company was founded by a former Facebook engineer Ben Dowling. IPInfo boasts an incredible amount of data sets and features as listed below:

  • Standard/Bulk/Requester lookups
  • Connection, Carrier related data
  • 🏛️ ASN IP Operator related proprietary data
  • Comprehensive GeoIP data form an IPInfo self-built solution
  • Specify fields to only get the data you want and save bandwidth
  • 🤯 Global ASN, Hosted Domains, and IP range data — one of it’s kind
$.get("https://ipinfo.io", function(response) {
console.log(response.ip, response.country);
}, "jsonp")

Returns:

Pros:

  • 30,000 API requests per month for free.
  • 100% uptime since it’s based on top of Amazon Web Services. The deployments are on a daily basis with Elastic Beanstalk. The API speed is pretty much unmatchable.
  • Data: Huge data sets for ASN, Carrier, etc can be very helpful in building content customization. Imagine targeting AT&T and T-Mobile users differently for your next ad campaign.
  • Enterprise Tested: IPInfo’s data has been sought by several enterprise companies, e.g. Tesla, Dell, TripAdvisor, and Xerox — which is a testament to how far they have come. Many SMB to Large-scale enterprise companies listed on the about page.

Limitations:

- 1,000 requests per day on the free plan.

geobytes.com

$.getJSON( '//gd.geobytes.com/GetCityDetails?callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"geobytesforwarderfor": "",
"geobytesremoteip": "119.152.180.314",
"geobytesipaddress": "119.152.180.314",
"geobytescertainty": "99",
"geobytesinternet": "SA",
"geobytescountry": "Saudi Arabia",
"geobytesregionlocationcode": "SASH",
"geobytesregion": "Ash Sharqiyah",
"geobytescode": "SH",
"geobyteslocationcode": "SASHJUBA",
"geobytescity": "Jubail",
"geobytescityid": "13793",
"geobytesfqcn": "Jubail, SH, Saudi Arabia",
"geobyteslatitude": "27.004999",
"geobyteslongitude": "49.660999",
"geobytescapital": "Riyadh ",
"geobytestimezone": "+03:00",
"geobytesnationalitysingular": "Saudi Arabian ",
"geobytespopulation": "22757092",
"geobytesnationalityplural": "Saudis",
"geobytesmapreference": "Middle East ",
"geobytescurrency": "Saudi Riyal",
"geobytescurrencycode": "SAR",
"geobytestitle": "Saudi Arabia"
}

Limitations:

- 16,384 requests per hour
- Can return the wrong location (I am not in Saudi Arabia)

geoip.nekudo.com

$.getJSON( '//geoip.nekudo.com/api/', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"city": "Pakistan",
"country": {
"name": "Pakistan",
"code": "PK"
},
"location": {
"accuracy_radius": 50,
"latitude": 1.2855,
"longitude": 103.8565,
"time_zone": "Asia/Karachi"
},
"ip": "119.152.180.314"
}

Limitations:

- Requires IP address parameter

geoplugin.com

$.getJSON( '//www.geoplugin.net/json.gp?jsoncallback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"geoplugin_request": "119.152.180.314",
"geoplugin_status": 200,
"geoplugin_credit": "Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.",
"geoplugin_city": "Pakistan",
"geoplugin_region": "Pakistan ( general )",
"geoplugin_areaCode": "0",
"geoplugin_dmaCode": "0",
"geoplugin_countryCode": "PK",
"geoplugin_countryName": "Pakistan",
"geoplugin_continentCode": "AS",
"geoplugin_latitude": "31.5497",
"geoplugin_longitude": "103.855797",
"geoplugin_regionCode": "00",
"geoplugin_regionName": "Pakistan ( general )",
"geoplugin_currencyCode": "PKD",
"geoplugin_currencySymbol": "Rs.",
"geoplugin_currencySymbol_UTF8": "Rs.",
"geoplugin_currencyConverter": 1.4239
}

Limitations:

- 120 requests per minute

ip-api.com

$.getJSON( '//ip-api.com/json?callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"as": "PTCL",
"city": "Pakistan",
"country": "Pakistan",
"countryCode": "PK",
"isp": "PTCL Pte Ltd",
"lat": 31.5497,
"lon": 74.3436,
"org": "Pakistan Telecommunications",
"query": "119.152.180.314",
"region": "01",
"regionName": "Central Pakistan Community Development Council",
"status": "success",
"timezone": "Asia/Karachi",
"zip": ""
}

Limitations:

- 150 requests per minute

ipify.org

$.getJSON( '//api.ipify.org?format=jsonp&callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"ip": "119.152.180.314"
}

Limitations:

- None (unlimited bandwidth)

ipinfodb.com

$.getJSON( '//api.ipinfodb.com/v3/ip-city/?key=&format=json&callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"statusCode": "OK",
"statusMessage": "",
"ipAddress": "119.152.180.314",
"countryCode": "PK",
"countryName": "Pakistan",
"regionName": "Pakistan",
"cityName": "Pakistan",
"zipCode": "54000",
"latitude": "1.28967",
"longitude": "103.85",
"timeZone": "+08:00"
}

Limitations:

- Two requests per second
- Requires registration to get your API key

jsonip.com

$.getJSON( '//jsonip.com/?callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"ip": "119.152.180.314",
"about": "/about",
"Pro!": "http://getjsonip.com"
}

Limitations:

- None (unlimited bandwidth)

jsontest.com

$.getJSON( '//ip.jsontest.com/?callback=?', function( data ) {
console.log( JSON.stringify( data, null, 2 ) );
});

Returns:

{
"ip": "119.152.180.314"
}

Limitations:

- Goes down a lot ( over quota ), so I wouldn’t use it for production.

IPData.co →

$.get("https://api.ipdata.co", function (response) {
$("#response").html(JSON.stringify(response, null, 4));
}, "jsonp"); Here's a JSFiddle

Returns:

{
"ip": "39.45.201.56",
"city": "Sialkot",
"region": "Punjab",
"region_code": "PB",
"country_name": "Pakistan",
"country_code": "PK",
"continent_name": "Asia",
"continent_code": "AS",
"latitude": 32.4228,
"longitude": 74.2898,
"asn": "AS45595",
"organisation": "Pakistan Telecom Company Limited",
"postal": "51310",
"calling_code": "92",
"flag": "https://ipdata.co/flags/pk.png",
"emoji_flag": "🇵🇰",
"emoji_unicode": "U+1F1F5 U+1F1F0",
"is_eu": false,
"languages": [
{
"name": "English",
"native": "English"
},
{
"name": "Urdu",
"native": "اردو",
"rtl": 1
}
],
"currency": {
"name": "Pakistani Rupee",
"code": "PKR",
"symbol": "PKRs",
"native": "₨",
"plural": "Pakistani rupees"
},
"time_zone": {
"name": "Asia/Karachi",
"abbr": "PKT",
"offset": "+0500",
"is_dst": false,
"current_time": "2018-04-18T21:22:54.352584+05:00"
},
"threat": {
"is_tor": false,
"is_proxy": false,
"is_anonymous": false,
"is_known_attacker": false,
"is_known_abuser": false,
"is_threat": false,
"is_bogon": false
}
}

Pros:

  • 1,500 requests daily for free.
  • 11 endpoints around the world, 4 in the US, 1 in Canada, 2 in Europe (London and Frankfurt), Mumbai, Seoul, Sydney and Sao Paulo. Being this global is a big plus.
  • 2x Speed as compared to others. If you take a look at this data you can see that IPData.co is quite fast as compared to other IP API Services — this matters a lot if you’re building a commercial site.
  • Extra data points i.e. calling code, currency code, name, symbol, time_zone data, current time, UTC offset and the flag file & emoji flag.
  • Enterprise level threat data — Only for paid users but have pretty great threat intelligence data to check if an IP is a proxy, a known attacker, abuser, tor user or a bogon.

Limitations:

  • Lesser free requests per day (but it’s a paid service which is far better than free services available, and is here to stay).
  • Wrong city analysis for me, which’s quite common. Not sure if it’s related to my ISP or what.

GeoIPify.WhoIsXMLAPI.com

var ip = "39.45.220.245";
var api_key = "your_api_key";
$(function () {
$.ajax({
url: "https://geoipify.whoisxmlapi.com/api/v1",
dataType: "jsonp",
data: {
apiKey: api_key,
ipAddress: ip
},
success: function (data) {
console.log(JSON.stringify(data, "", 2));
}
});
});

Returns:

Result for 39.45.220.245
Country: PK
Region: Punjab
City: Sialkot
Latitude: 32.5101
Longitude: 74.54313
Postal code: 51260
Time zone offset by UTC: +05:00

Pros:

  • 1,000 requests per month for free.
  • Three payment tiers you can use it for free, pay one time, or go ahead and subscribe on a monthly to yearly basis.
  • Awesome clientele with lots of related solutions like WHOIS/DNS lookup service, email verification, reverse IP lookup, to go along with GEO IP API.

Limitations:

  • 1,000 requests per month
  • Requires IP address parameter
  • Requires an email address to get your API key
  • Lesser free requests per day (but it’s a paid service which is far better than free services available, and is here to stay).

IPGeoLocation.io

//api.ipgeolocation.io/ipgeo?apiKey=API_KEY

Returns:

{
"ip": "39.45.201.56",
"continent_code": "AS",
"continent_name": "Asia",
"country_code2": "PK",
"country_code3": "PAK",
"country_name": "Pakistan",
"country_capital": "Islamabad",
"state_prov": "Khyber Pakhtunkhwa",
"district": "Peshawar",
"city": "Peshawar",
"zipcode": "25120",
"latitude": "34.015",
"longitude": "71.5805",
"is_eu": false,
"calling_code": "+92",
"country_tld": ".pk",
"languages": "ur-PK,en-PK,pa,sd,ps,brh",
"country_flag": "https://ipgeolocation.io/static/flags/pk_64.png",
"isp": "PTCL Triple Play Project Sialkot",
"connection_type": "",
"organization": "Pakistan Telecommuication company limited",
"geoname_id": "1168197",
"currency": {
"name": "Rupee",
"code": "PKR"
},
"time_zone": {
"name": "Asia/Karachi",
"offset": 5,
"is_dst": false,
"current_time": "2018-06-16 16:07:07.708+0500"
}
}

Pros:

  • 50,000 requests per month for free without any daily limit.
  • Extra data points such as currency, the local language, time zone, flags, ISO2 and ISO3 country codes, and company information.
  • Economical paid plans — this service is here to stay.

Limitations:

  • Requires an email address to get your API key.

Before You Begin!

Keep in mind that since these are all free services, your mileage may vary in terms of exceeding quota and uptime, and who knows when/if they will be taken offline down the road. Most of these services also offer a paid tier in case you want something more robust.

It’d be a good thing if you tweet this list. No pressure!

JUST A NOTE!
👨‍💻 I’m teaching thousands of devs how to become
VSCode Power Users

Originally published at ahmadawais.com on June 11, 2017.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store