Ping (zestyping) wrote,

I'm processing some log data coming in from around the world, so I thought it would be nice to be able to look up IP addresses by country. Although more specific geographic data on IP numbers seems to be available only for a price, the country mapping is available for free in the Perl module Geo::IPfree.

I've turned this into a Python module, Unlike the Perl package, which stores the database in an auxiliary file, this Python module is just a single file containing the entire database and a simple lookup function. It's a bit big (nearly a megabyte), but it's easy to use and it works.
>>> import ipfree
>>> ipfree.lookup('')
('CA', 'Canada')
>>> ipfree.lookup('')
('NL', 'Netherlands')
Hope someone out there has a use for it.
  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.