When I use search engines for certain searches, mainly related to maps or commercial establishments, these systems usually provide me with results relevant to my geographic location.
When I'm on the PC, search engines may not even know my geographic position with GPS accuracy, but they at least know which city I'm in.
I believe this is determined by the IP address, as generally a specific address range is provided by the provider for very specific regions.
But at the level of implementation, how is this determination made? Is there a formula to determine the user's city or region based on their address? Or at least a known provider from which we can consume a service to obtain this information?
This is actually very simple and works like this:
- Operators provide IP numbers according to a range
- Track registration is done by location
- Depending on the quantity, this could be a building, street, neighborhood or city
- In order to facilitate the tracking of crimes, this information is updated in a database
- Operators exchange this information with their regulators
Once a month this bank is updated for the public
That database is the GeoLite Database .
A file in binary or CSV format, with all current IP blocks:
GeoIP Legacy Downloadable Databases
There are several ways to find an IP in this bank. Among the ready-made ways are:
- GeoLite CSV Java – Simple Example
- GeoIP2 Apache – Module for Apache Server
- GeoIP2 Binary Databases – Advanced Examples in Various Programming Languages