in reply to IP Lookup Tables

I pull GeoIP data into a PostgreSQL database and do the lookups from there. Here's my writeup from 2018 (the software still works fine on my system, no guarantees though): GeoIP revisited

PostgreSQL is nice for this, since it supports CIDR address ranges, you can do stuff like this:

SELECT country_code, city_name, latitude, longitude, radius FROM geoip WHERE ? << netblock LIMIT 1

With the proper GIST index, it works reasonably fast, too.

CREATE INDEX geoip_netblock_idx ON geoip USING GIST(netblock inet_ops);

Cables_DB=# SELECT country_code, city_name, latitude, longitude, radiu +s FROM geoip WHERE '8.8.8.8' << netblock LIMIT 1; country_code | city_name | latitude | longitude | radius --------------+-----------+----------+-----------+-------- US | | 37.751 | -97.822 | 1000 (1 row) Cables_DB=# EXPLAIN SELECT country_code, city_name, latitude, longitud +e, radius FROM geoip WHERE '8.8.8.8' << netblock LIMIT 1; QUERY PLAN + ---------------------------------------------------------------------- +----------------- Limit (cost=0.41..8.43 rows=1 width=35) -> Index Scan using geoip_netblock_idx on geoip (cost=0.41..8.43 +rows=1 width=35) Index Cond: ((netblock)::inet >> '8.8.8.8'::inet) (3 rows)

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP