Create an IP to location web service
In this tutorial, we demonstrate how to create an IP to location index and then serve it in a simple web application.
Dataset
The data used to create an IP to location index is publicly available from the 5 Regional Internet Registries (RIRs) (opens in a new tab)
Here is the list of the 5 RIRs.
- ARIN (opens in a new tab)
- LACNIC (opens in a new tab)
- AFRINIC (opens in a new tab)
- RIPE NCC (opens in a new tab)
- APNIC (opens in a new tab)
These Regional Internet Registries contain records that link IP address ranges to organisations along with some metadata. It is not always possible to extract meaningful data from these registries because they are not normalised.
Generate the index
The workflow executed in the following command contains multiple steps.
- Download and decompress the data from the RIRs
- Download and create a Geocoding index (see the Geocoding example)
- Iterate over every entry in the registries to extract the IP address ranges and the associated metadata to query the Geocoding index and extract a latitude and a longitude.
baremaps workflow execute --file examples/ip-to-location/workflow.js
Serve the data
The following command will serve the Geonames index over HTTP in a simple web application.
baremaps iploc serve --database iploc.db --port 9000
Go to http://localhost:9000/ (opens in a new tab) to see it in action.
Conclusion
In this tutorial, we learnt how to create an IP to location index and serve it in a simple web application. IP to location has many uses, one of which is to locate users that connect to a website to generate statistics.