Understanding the Basics of IP Address
Before we dive into IP geolocation, let's briefly talk about what an IP address is.
Definition of IP Address
An IP address is a string of numbers that identifies a device to the internet. Every device that is connected to the web has a separate and unique IP that is used to send and receive network requests. Think of an IP address as a computer’s home address. While an IP address can’t reveal any personal information like your age, sex, or exact location, it can be used to look up geographic information.
An IP address changes based on where the computer is accessing the network from. Your computer's IP address at the local coffee shop will be different from its IP address at home.
There are two main formats for IP addresses: IPv6 and IPv4. IPv4 addresses are the ones that most people are familiar with. They look like this:
Each segment of the address is an 8-bit field. Each 8-bit field represents a byte of the address. There are 4 8-bit fields, so it is a 32-bit address. This format is often referred to as the 'dotted decimal' format.
IPv6 addresses look like this:
Each segment of an IPv6 address is any hexadecimal value between 0 and FFFF. IPv6 is a 128-bit address. This means that IPv6 offers 1,028 times more addresses than IPv4, which means we will not run out of available IPv6 addresses as more devices come online in the future.
Types of IP Addresses
In addition to the different formats of IP addresses, there are a few different types of IP addresses for every device, depending on where the device is, and where it is being accessed from.
A device has a private address that identifies it to the local network (for example, the network that runs off the router in your home.) It also has a public address, which is actually the IP address of your router, provided by your Internet Service Provider. It also has a local address (127.0.0.1 or localhost), and several others.
How IP Addresses are Assigned
IP addresses are mathematically produced and allocated by the Internet Assigned Numbers Authority (IANA.) They can be assigned to a device statically or dynamically. A static IP address will be assigned only once, and will be the same IP address that the machine uses to access the internet every time it logs on.
A dynamically assigned IP will change each time the device connects to the internet. A new address is generated at the start of every session.
What is IP Geolocation and How Does it Work?
IP geolocation is used to identify visitor's geographical location via their IP. Geolocation just means using data available through devices (such as GPS or IP) to figure out geographical location in the real world.
Techniques Used for IP Geolocation
The typical way in which geolocation data is gathered is by examining the IP address of an incoming request, then sending that IP address to an API or other online service that will use an IP database to look up the IP address and return the user's location.
Limitations of IP Geolocation
IP geolocation database instances are maintained by third parties, and the accuracy of the data within them depends largely on the methods used to collect the data, and the reliability of the party doing the data collection.
Many IP companies acquire their data through data mining, while others get more accurate data through user polls. Depending on the database you choose, the data you get could be collected via either method.
Additionally, as previously mentioned, IP geolocation data is not 100% accurate. You won't get personal information, or even be able to identify visitors' geographical location data down to a street address. You won't get a phone number or an idd country code. Most services return a radius within which the device is likely to be.
Benefits of Using an IP Database
Now that we know what an IP address is and how it can help us look up users' locations, let's talk about how a location database can help improve our website visitors' experiences.
One of the most popular use cases for gathering IP geolocation data about your users is so that you can serve them highly targeted ads. Knowing a user's area code, for example, can be used to point them toward a brick-and-mortar store close to them.
You can also serve ads in the right language, show prices in the right currencies, and only show users ads that are relevant to them. Users who live in the country, for example, are unlikely to buy the same things as users who live in cities.
By far the most important use of IP geolocation data is to prevent online fraud. Many online banks, credit card companies, and other financial institutions use user locations to determine whether a login request is fraudulent.
If a login attempt is made from an unexpected location - another country or even just another city, the website can prevent the login and alert the user that the account may have been comprised.
Another use of IP geolocation database data in preventing online fraud is to protect sites from DDOS (Distributed Denial of Service) attacks. Requests can be blocked from countries that are known to spawn a lot of these types of attacks, thus thwarting many attempts and keeping sites safe.
Improved User Experience
Knowing your user's IP address and physical location can also help you to improve their online experience on your site. You can show them language translations and currency conversions, as well as content that is most relevant to them.
Localizing content in this way makes it easier for users to browse your site and makes it more likely that they will make a purchase or become returning visitors
Geographic Content Restriction
Finally, geographical location data can be used to restrict content in certain countries or regions. Many streaming services such as Netflix use this method to prevent content from being accessed in countries in which it is not licensed to play.
Types of IP Databases
When it comes to utilizing IP database information, there are a couple of different types, and the quality of the data in them may be different depending on the type. Additionally, connection speed, regulatory compliance, and other factors may change based on the type of database you use.
A commercial IP database is run for profit by a third-party company that specializes in providing geographical location data to its customers. They typically have increased accuracy over the free IP database options available, and their data collection methods are usually sound and comply with government regulations.
Here are a few of the most popular commercial IP database options:
- IP2Location - provides IP-based geolocation data as well as other types of data including weather station code information, zip code to metro data, information on proxy servers, and more
- Maxmind - database specializing in online fraud prevention
- IPIP - downloadable database based on analysis of real-time BGP/ASN data
Free IP Databases
Free online databases can be less accurate than commercial ones but are usually good enough for small businesses, freelancers, and hobbyists. Some of the most popular free options include:
- IP2Location LITE - a free version of the IP2Location database
- MaxMind's GeoLite2 Database
How to Choose the Right IP Database
Once you've decided that using Ip address data to determine your users' physical location is important, you'll need to evaluate some database options to decide which one is right for you. We recommend using the following criteria to make your decision.
As mentioned, the accuracy of geolocation data, in general, is not pinpoint perfect. You will only be able to narrow it down to a city and radius within some longitude and latitude points. That being said, some servers will provide more accurate data than others.
Frequency of Updates
Make sure that the data in the database is updated regularly. Stale data is as useless as no data - in fact, it can be worse than having no data, because you might serve your users incorrect content based on an inaccurate location.
How many locations does the database provide data for? There may be gaps in the coverage map. This could be fine if you know that you don't have users in certain locations, but you should check where those gaps in the data are before you decide to use a service.
Before choosing a service, do a thorough audit of your specific needs to determine what you need the database to handle. How much flexibility does the service have? Can you do an IP address database download if need be?
Finally, consider the cost of the service. We leave this until last because it's worth paying for features that you need, rather than limiting yourself by cost upfront. If a service is a little more expensive but provides more accurate data and better features, it's worth paying for it.
How to Implement an IP Database
The simplest way to implement an IP database is through an API. There are many geolocation APIs out there that connect to reliable, well-managed IP databases and make the process of gathering geographical location data about your users very easy.
Let's take a look at how to use the AbstractAPI Free Geolocation API to look up a user location based on an IP address.
Get an API Key
In order to use the API, you'll need to sign up for a free account and obtain an API key. The APi key authenticates you to the API and allows you to make requests. Your account is always free, and there are no ads or mailing lists to join. You can make up to 20,000 requests at 1 request per second.
Go to the API homepage and click "Get Started."
You'll need to input your email address and create a password. Then you'll be taken to the dashboard, where you'll see a testing sandbox and your API key.
Make a Request to the API
This code sends a GET request to the API endpoint, with your API key included as a query parameter in the URL. That's all you need to get geolocation information from the API.
You can also include an IP address as a query parameter in the URL. If no IP address is provided, the API will automatically pull the IP address of the machine that sent the request.
Please note that some identifying information has been redacted from this output.
The API returns an object with detailed information about the user's city, state, region, country code, and area code, as well as other information like their ISP, timezone, currency, and even a country flag emoji.
You can now pull the relevant fields off the object and use them in your code. For example, grab the latitude and longitude values and use them to render a location for your user on a map.
Best Practices for Using IP Geolocation Database
When using sensitive information like user location on your sites, you must make sure you are complying with data privacy regulations and that you are ensuring data security for your users.
Additionally, you should never use a user's location to engage in discriminatory practices against that user.
Finally, monitor the IP datasets you return and the performance of the database to make sure that slow requests or stale data aren't impacting your users' experiences on your site.
Limitations and Challenges of Geolocation Data
There are many challenges to using geolocation data. Most commonly, the issue site owners come up against is the use of VPNs and proxy servers by users to maintain their privacy and circumvent IP lookups.
A VPN or proxy will mask the user's real IP address, allowing them to download content in regions they should not be able to access or to make fraudulent requests that look like they come from other places.
It is also possible to become over-reliant on geolocation data obtained through IP addresses. There are many other ways of determining user location, such as through GPS, automated address geocoding, or desktop geolocation.
Being able to identify visitors' geographical location data is a powerful tool for providing a secure and enjoyable experience for your users. You can use geolocation data to prevent online fraud, serve targeted ads, localize web pages, and geoblock content.
If you're interested in getting started with an IP geolocation database, check out some of the options listed in this article. Utilizing an API like the AbstractAPI Free IP Geolocation API is a quick and easy way to start accessing geographical location data about your users.
What is an IP Geolocation Database?
A geolocation database allows you to look up a user's physical location based on an IP address. Most geolocation APIs (both free and paid) rely on IP location databases for their information. There are free and paid databases available, and the quality of the data may differ depending on the service.
How does IP Geolocation work?
Each device connected to the internet has a unique IP that identifies it to the network and allows other machines to make and receive requests to and from that device. The unique string of bytes can be mapped to a physical location that can tell you the city, state, region, and country from which the device is accessing the internet.
What are the benefits of an IP Database?
Geolocation can be used to target ads, serve localized web pages and currency information, block content in certain regions, and prevent bad actors from certain places from engaging in fraudulent activity.
How accurate is IP Geolocation?
Geolocation done by IP will not give you a street address, phone number, person's name or any other personally identifying information. You can get latitude and longitude coordinates and learn the city, state, region, and country that the user is in.