I'm trying to limit my number of requests to an IP geolocation API,I want to know if this will accurately determine user country;
1 | 1.194.121.200 | USA
If I have the above in my Database, can I use same country for an IP (1.194.208.105) having same integers in their first two octets, to avoid another API request?
Not reliably, no.
Eg: A few years ago Azure had problems because they bought a block of IPs from LACNIC [south america] to use in their US-based cloud. This caused all sorts of havoc because people using stale IP registration/geolocation data started complaining that they didn't want their data located outside of the US.
By all means cache the per-IP results for a reasonable period, but you're not going to be able to cache by netblock unless either your API provider gives you that data, or you want build your own IP geolocation service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.