Commit 2df4b7b2 by William Tisäter

Add syntax color to code examples in README

parent 2ebe2164
# Pure Python GeoIP API # # Pure Python GeoIP API
This library is based on [Maxmind's GeoIP C API](https://github.com/maxmind/geoip-api-c). This library is based on [Maxmind's GeoIP C API](https://github.com/maxmind/geoip-api-c).
...@@ -6,97 +6,114 @@ Tested with Python version 2.5, 2.6, 2.7, 3.2 and 3.3. ...@@ -6,97 +6,114 @@ Tested with Python version 2.5, 2.6, 2.7, 3.2 and 3.3.
[![Build Status](https://api.travis-ci.org/appliedsec/pygeoip.png?branch=master)](https://travis-ci.org/appliedsec/pygeoip) [![Coverage Status](https://coveralls.io/repos/appliedsec/pygeoip/badge.png)](https://coveralls.io/r/appliedsec/pygeoip) [![Downloads](https://pypip.in/d/pygeoip/badge.png)](https://crate.io/packages/pygeoip) [![Build Status](https://api.travis-ci.org/appliedsec/pygeoip.png?branch=master)](https://travis-ci.org/appliedsec/pygeoip) [![Coverage Status](https://coveralls.io/repos/appliedsec/pygeoip/badge.png)](https://coveralls.io/r/appliedsec/pygeoip) [![Downloads](https://pypip.in/d/pygeoip/badge.png)](https://crate.io/packages/pygeoip)
## Installation ## ## Installation
You can easily install pygeoip from PyPi. You can easily install pygeoip from PyPi.
pip install pygeoip ```bash
pip install pygeoip
```
## Supported Databases ## ## Issues and Contribution
* COUNTRY_EDITION
* COUNTRY_EDITION_V6
* REGION_EDITION_REV0
* REGION_EDITION_REV1
* CITY_EDITION_REV0
* CITY_EDITION_REV1
* CITY_EDITION_REV1_V6
* ORG_EDITION
* ISP_EDITION
* ASNUM_EDITION
* ASNUM_EDITION_V6
## Issues and Contribution ##
Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission. Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission.
## Getting Started ## ## Getting Started
Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap. Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap.
import pygeoip ```python
gi4 = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE) >>> import pygeoip
gi6 = pygeoip.GeoIP('/path/to/GeoIPv6.dat', pygeoip.MEMORY_CACHE) >>> gi = pygeoip.GeoIP('/path/to/GeoIP.dat')
>>> gi.country_name_by_addr('64.233.161.99')
### Country Lookup ### 'United States'
```
>>> gi4.country_code_by_name('google.com')
'US' ### Country Lookup
>>> gi4.country_code_by_addr('64.233.161.99')
'US' ```python
>>> gi4.country_name_by_addr('64.233.161.99') >>> gi = pygeoip.GeoIP('/path/to/GeoIP.dat')
'United States' >>> gi.country_code_by_name('google.com')
>>> gi6.country_code_by_name('google.com') 'US'
'IE' >>> gi.country_code_by_addr('64.233.161.99')
>>> gi6.country_code_by_addr('2001:7fd::1') 'US'
'EU' >>> gi.country_name_by_addr('64.233.161.99')
>>> gi6.country_name_by_addr('2001:7fd::1') 'United States'
'Europe' ```
### Region Lookup ### ```python
>>> gi = pygeoip.GeoIP('/path/to/GeoIPv6.dat')
>>> gi = pygeoip.GeoIP('/path/to/GeoIPRegion.dat') >>> gi.country_code_by_name('google.com')
>>> gi.region_by_name('apple.com') 'IE'
{'region_code': 'CA', 'country_code': 'US'} >>> gi.country_code_by_addr('2001:7fd::1')
'EU'
>>> gi.country_name_by_addr('2001:7fd::1')
'Europe'
```
### Region Lookup
```python
>>> gi = pygeoip.GeoIP('/path/to/GeoIPRegion.dat')
>>> gi.region_by_name('apple.com')
{'region_code': 'CA', 'country_code': 'US'}
```
### City Lookup ### ### City Lookup ###
>>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat') ```python
>>> gi.record_by_addr('64.233.161.99') >>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
{ >>> gi.record_by_addr('64.233.161.99')
'city': u'Mountain View', {
'region_code': u'CA', 'city': u'Mountain View',
'area_code': 650, 'region_code': u'CA',
'time_zone': 'America/Los_Angeles', 'area_code': 650,
'dma_code': 807, 'time_zone': 'America/Los_Angeles',
'metro_code': 'San Francisco, CA', 'dma_code': 807,
'country_code3': 'USA', 'metro_code': 'San Francisco, CA',
'latitude': 37.41919999999999, 'country_code3': 'USA',
'postal_code': u'94043', 'latitude': 37.41919999999999,
'longitude': -122.0574, 'postal_code': u'94043',
'country_code': 'US', 'longitude': -122.0574,
'country_name': 'United States', 'country_code': 'US',
'continent': 'NA' 'country_name': 'United States',
} 'continent': 'NA'
>>> gi.time_zone_by_addr('64.233.161.99') }
'America/Los_Angeles' >>> gi.time_zone_by_addr('64.233.161.99')
'America/Los_Angeles'
### Organization Lookup ### ```
>>> gi = pygeoip.GeoIP('/path/to/GeoIPOrg.dat') ### Organization Lookup
>>> gi.org_by_name('dell.com')
'Dell Computer Corporation' ```python
>>> gi = pygeoip.GeoIP('/path/to/GeoIPOrg.dat')
### ISP Lookup ### >>> gi.org_by_name('dell.com')
'Dell Computer Corporation'
>>> gi = pygeoip.GeoIP('/path/to/GeoIPISP.dat') ```
>>> gi.org_by_name('cnn.com')
'Turner Broadcasting System' ### ISP Lookup
### ASN Lookup ### ```python
>>> gi = pygeoip.GeoIP('/path/to/GeoIPISP.dat')
>>> gi = pygeoip.GeoIP('/path/to/GeoIPASNum.dat') >>> gi.org_by_name('cnn.com')
>>> gi.org_by_name('cnn.com') 'Turner Broadcasting System'
'AS5662 Turner Broadcasting' ```
### ASN Lookup
```python
>>> gi = pygeoip.GeoIP('/path/to/GeoIPASNum.dat')
>>> gi.org_by_name('cnn.com')
'AS5662 Turner Broadcasting'
```
For more information, [check out the full API documentation](http://packages.python.org/pygeoip). For more information, [check out the full API documentation](http://packages.python.org/pygeoip).
## Supported Databases
* Country IPv4 and IPv6
* City IPv4 and IPv6
* Organization IPv4
* ISP IPv4
* Region IPv4
* ASNum IPv4 and IPv6
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment