Mapping IP addresses to geolocations is done via tables, where an IP maps to a particular location. This location, however, doesn’t need to be accurate, since IP addresses don’t carry any information about their locations, these are approximated.
From Wikipedia’s article on Internet geolocation:
The primary source for IP address data is the regional Internet registries which allocate and distribute IP addresses amongst organizations located in their respective service regions:
- African Network Information Centre (AfriNIC)
- American Registry for Internet Numbers (ARIN)
- Asia-Pacific Network Information Centre (APNIC)
- Latin American and Caribbean Internet Address Registry (LACNIC)
- RIPE Network Coordination Centre (RIPE NCC)
Secondary sources include:
- Data mining or user-submitted geographic location data:
- Website-submitted, e.g. a weather website asking visitors for a city name to find their local forecast or pairing a user’s IP address with the address information in their account profile.
- Wi-Fi positioning system through the examination of neighborhood Wi-Fi BSSID. E.g. Mozilla Location Service.
- Examination of neighborhood Bluetooth devices.
- Pairing a user’s IP address with the GPS location of a device that’s using such an IP address.
- Data contributed by Internet service providers.
- Guesstimates from adjacent Class C range and/or gleaned from network hops.
- Network routing information collected to the end point of IP address.
- Analysis of linguistic data from the device, using pretrained models that show that some term is frequently mentioned in a certain location (e.g. “the T” vs “the El” vs. “the subway”).
Accuracy is improved by:
- Data scrubbing to filter out or identify anomalies.
- Statistical analysis of user submitted data.
- Utilizing third-party tests conducted by reputable organizations.