diff options
Diffstat (limited to 'cgi/geoip.py')
-rw-r--r-- | cgi/geoip.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/cgi/geoip.py b/cgi/geoip.py index 0bcb3d8..36c25d1 100644 --- a/cgi/geoip.py +++ b/cgi/geoip.py @@ -41,6 +41,7 @@ countries = ( 'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA', 'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1', 'AX', 'GG', 'IM', 'JE', 'BL', 'MF') + def iptonum(ip): """Convert IP address string to 32-bit integer, or return None if IP is bad. @@ -70,9 +71,11 @@ def iptonum(ip): num = num << 8 | segment return num + class DatabaseError(Exception): pass + class GeoIP(object): """Wraps GeoIP country database lookup into a class.""" @@ -119,10 +122,12 @@ class GeoIP(object): offset = x[i] raise DatabaseError('GeoIP database corrupt: offset=%s' % offset) + def country(ip, dbname='GeoIP.dat'): """Helper function that creates a GeoIP instance and calls country().""" return GeoIP(dbname).country(ip) + if __name__ == '__main__': import doctest doctest.testmod() |