class - geoip

 

 


Install

 

Linux:

pip install pygeoip

Windows:

easy_install.exe pygeoip

Source:

https://code.google.com/p/pygeoip/downloads/list

GeoIP.dat Download:

GeoLite License: Creative Commons Attribution-ShareAlike 3.0 Unported License

 


Usage Example:


import pygeoip

# Country Database

gi = pygeoip.GeoIP('/path/to/GeoIP.dat')

# 2-letter country code (e.g. HK)
gi.country_code_by_name('hkbn.net')
gi.country_code_by_addr('61.92.45.74')


# City Database

gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
gic.record_by_addr('64.233.161.99')
gic.record_by_name('google.com')
# {'city': 'Mountain View', 'region_name': 'CA', 'area_code': 650, 'longitude': -122.0574, 'country_code3': 'USA', 'latitude': 37.419199999999989, 'postal_code': '94043', 'dma_code': 807, 'country_code': 'US', 'country_name': 'United States'}

gic.region_by_name('google.com')
gic.region_by_addr('64.233.161.99')
# {'region_name': 'CA', 'country_code': 'US'}






Creative Commons license icon Creative Commons license icon