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

In reply to Re: IP Lookup Tables by cavac
in thread IP Lookup Tables by monsignor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.