| OLD | NEW |
| (Empty) |
| 1 # Pure Python GeoIP API # | |
| 2 The API is based on [MaxMind's C-based Python API](http://dev.maxmind.com/geoip/
downloadable#Python-5), | |
| 3 but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/
package/Net_GeoIP) by Jim Winstead and Hans Lellelid. | |
| 4 | |
| 5 It is mostly a drop-in replacement, except the `new` and `open` methods are gone
. | |
| 6 | |
| 7 Tested using tox with Python version 2.5, 2.6, 2.7, 3.1, 3.2 and 3.3. | |
| 8 | |
| 9 ## Issues and contribution ## | |
| 10 | |
| 11 Bug reports are done by [creating an issue on Github](https://github.com/applied
sec/pygeoip/issues). If you want to contribute you can always [create a pull req
uest](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submi
ssion. | |
| 12 | |
| 13 ## Installation ## | |
| 14 | |
| 15 You can easily install pygeoip with setuptools: | |
| 16 | |
| 17 easy_install pygeoip | |
| 18 | |
| 19 ## Supported Databases ## | |
| 20 | |
| 21 * Country | |
| 22 * Region | |
| 23 * City | |
| 24 * Organization | |
| 25 * ISP | |
| 26 * ASN | |
| 27 | |
| 28 ## Quick Documentation ## | |
| 29 | |
| 30 Create your GeoIP instance with appropriate access flag. `STANDARD` reads data f
rom disk when needed, `MEMORY_CACHE` loads database into memory on instantiation
and `MMAP_CACHE` loads database into memory using mmap. | |
| 31 | |
| 32 import pygeoip | |
| 33 gi4 = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE) | |
| 34 gi6 = pygeoip.GeoIP('/path/to/GeoIPv6.dat', pygeoip.MEMORY_CACHE) | |
| 35 | |
| 36 ### Country lookup ### | |
| 37 | |
| 38 >>> gi4.country_code_by_name('google.com') | |
| 39 'US' | |
| 40 >>> gi4.country_code_by_addr('64.233.161.99') | |
| 41 'US' | |
| 42 >>> gi4.country_name_by_addr('64.233.161.99') | |
| 43 'United States' | |
| 44 >>> gi6.country_code_by_name('google.com') | |
| 45 'IE' | |
| 46 >>> gi6.country_code_by_addr('2001:7fd::1') | |
| 47 'EU' | |
| 48 >>> gi6.country_name_by_addr('2001:7fd::1') | |
| 49 'Europe' | |
| 50 | |
| 51 ### Region lookup ### | |
| 52 | |
| 53 >>> gi = pygeoip.GeoIP('/path/to/GeoIPRegion.dat') | |
| 54 >>> gi.region_by_name('apple.com') | |
| 55 {'region_name': 'CA', 'country_code': 'US'} | |
| 56 | |
| 57 ### City lookup ### | |
| 58 | |
| 59 >>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat') | |
| 60 >>> gi.record_by_addr('64.233.161.99') | |
| 61 { | |
| 62 'city': 'Mountain View', | |
| 63 'region_name': 'CA', | |
| 64 'area_code': 650, | |
| 65 'longitude': -122.0574, | |
| 66 'country_code3': 'USA', | |
| 67 'latitude': 37.419199999999989, | |
| 68 'postal_code': '94043', | |
| 69 'dma_code': 807, | |
| 70 'country_code': 'US', | |
| 71 'country_name': 'United States', | |
| 72 'continent': 'NA' | |
| 73 } | |
| 74 >>> gi.time_zone_by_addr('64.233.161.99') | |
| 75 'America/Los_Angeles' | |
| 76 | |
| 77 ### Organization lookup ### | |
| 78 | |
| 79 >>> gi = pygeoip.GeoIP('/path/to/GeoIPOrg.dat') | |
| 80 >>> gi.org_by_name('dell.com') | |
| 81 'Dell Computer Corporation' | |
| 82 | |
| 83 ### ISP lookup ### | |
| 84 | |
| 85 >>> gi = pygeoip.GeoIP('/path/to/GeoIPISP.dat') | |
| 86 >>> gi.org_by_name('cnn.com') | |
| 87 'Turner Broadcasting System' | |
| 88 | |
| 89 ### ASN lookup ### | |
| 90 | |
| 91 >>> gi = pygeoip.GeoIP('/path/to/GeoIPASNum.dat') | |
| 92 >>> gi.org_by_name('cnn.com') | |
| 93 'AS5662 Turner Broadcasting' | |
| 94 | |
| 95 For more information, [check out the full API documentation](http://packages.pyt
hon.org/pygeoip). | |
| OLD | NEW |