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 Internet routing registries (IRRs) (opens in a new tab) which includes the Regional Internet Registries (RIRs) (opens in a new tab)
The data are formatted following RPSL (opens in a new tab) specifications and contain records that link IP address ranges to organisations along with some metadata.
Generate the index
cd examples/ip-to-location
baremaps workflow execute --file workflow.js
The workflow executed in the above command does the following:
- Download and decompress the data from the IRRs
- 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.
Serve the data
baremaps iploc serve --database iploc.db --port 9000
A simple web application serves the Geonames index. Go to your browser (http://localhost:9000/
) 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.