Ping (zestyping) wrote,
Ping
zestyping

ipfree.py

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, ipfree.py. 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('129.97.128.15')
('CA', 'Canada')
>>> ipfree.lookup('194.109.137.226')
('NL', 'Netherlands')
>>>
Hope someone out there has a use for it.
Subscribe
  • Post a new comment

    Error

    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.
  • 12 comments