Package pygeoip :: Class GeoIP
[hide private]
[frames] | no frames]

Class GeoIP

source code

object --+    
         |    
 GeoIPBase --+
             |
            GeoIP

Instance Methods [hide private]
 
__init__(self, filename, flags=0)
Initialize the class.
source code
 
_setup_segments(self)
Parses the database file to determine what kind of database is being used and setup segment sizes and start points that will be used by the seek*() methods later.
source code
int
_seek_country(self, ipnum)
Using the record length and appropriate start points, seek to the country that corresponds to the converted IP address integer.
source code
str
_get_org(self, ipnum)
Seek and return organization or ISP name for ipnum.
source code
dict
_get_region(self, ipnum)
Seek and return the region info (dict containing country_code and region_name).
source code
dict
_get_record(self, ipnum)
Populate location dict for converted IP.
source code
 
_gethostbyname(self, hostname) source code
int
id_by_addr(self, addr)
Get the country index.
source code
str
country_code_by_addr(self, addr)
Returns 2-letter country code (e.g.
source code
str
country_code_by_name(self, hostname)
Returns 2-letter country code (e.g.
source code
str
country_name_by_addr(self, addr)
Returns full country name for specified IP address.
source code
str
country_name_by_name(self, hostname)
Returns full country name for specified hostname.
source code
str
org_by_addr(self, addr)
Lookup Organization, ISP or ASNum for given IP address.
source code
str
org_by_name(self, hostname)
Lookup the organization (or ISP) for hostname.
source code
dict
record_by_addr(self, addr)
Look up the record for a given IP address.
source code
dict
record_by_name(self, hostname)
Look up the record for a given hostname.
source code
dict
region_by_addr(self, addr)
Lookup the region for given IP address.
source code
dict
region_by_name(self, hostname)
Lookup the region for given hostname.
source code
str
time_zone_by_addr(self, addr)
Look up the time zone for a given IP address.
source code
str
time_zone_by_name(self, hostname)
Look up the time zone for a given hostname.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename, flags=0)
(Constructor)

source code 

Initialize the class.

Parameters:
  • filename (str) - Path to a geoip database.
  • flags (int) - Flags that affect how the database is processed. Currently supported flags are STANDARD (the default), MEMORY_CACHE (preload the whole file into memory) and MMAP_CACHE (access the file via mmap).
Overrides: object.__init__

_setup_segments(self)

source code 

Parses the database file to determine what kind of database is being used and setup segment sizes and start points that will be used by the seek*() methods later.

Supported databases:

* COUNTRY_EDITION * COUNTRY_EDITION_V6 * REGION_EDITION_REV0 * REGION_EDITION_REV1 * CITY_EDITION_REV0 * CITY_EDITION_REV1 * ORG_EDITION * ISP_EDITION * ASNUM_EDITION

_seek_country(self, ipnum)

source code 

Using the record length and appropriate start points, seek to the country that corresponds to the converted IP address integer.

Parameters:
  • ipnum (int) - result of ip2long conversion
Returns: int
offset of start of record

_get_org(self, ipnum)

source code 

Seek and return organization or ISP name for ipnum.

Parameters:
  • ipnum (int) - Converted IP address
Returns: str
org/isp name

_get_region(self, ipnum)

source code 

Seek and return the region info (dict containing country_code and region_name).

Parameters:
  • ipnum (int) - Converted IP address
Returns: dict
dict containing country_code and region_name

_get_record(self, ipnum)

source code 

Populate location dict for converted IP.

Parameters:
  • ipnum (int) - Converted IP address
Returns: dict
dict with country_code, country_code3, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_name, time_zone

id_by_addr(self, addr)

source code 

Get the country index. Looks up the index for the country which is the key for the code and name.

Parameters:
  • addr (str) - The IP address
Returns: int
network byte order 32-bit integer

country_code_by_addr(self, addr)

source code 

Returns 2-letter country code (e.g. 'US') for specified IP address. Use this method if you have a Country, Region, or City database.

Parameters:
  • addr (str) - IP address
Returns: str
2-letter country code

country_code_by_name(self, hostname)

source code 

Returns 2-letter country code (e.g. 'US') for specified hostname. Use this method if you have a Country, Region, or City database.

Parameters:
  • hostname (str) - Hostname
Returns: str
2-letter country code

country_name_by_addr(self, addr)

source code 

Returns full country name for specified IP address. Use this method if you have a Country or City database.

Parameters:
  • addr (str) - IP address
Returns: str
country name

country_name_by_name(self, hostname)

source code 

Returns full country name for specified hostname. Use this method if you have a Country database.

Parameters:
  • hostname (str) - Hostname
Returns: str
country name

org_by_addr(self, addr)

source code 

Lookup Organization, ISP or ASNum for given IP address. Use this method if you have an Organization, ISP or ASNum database.

Parameters:
  • addr (str) - IP address
Returns: str
organization or ISP name

org_by_name(self, hostname)

source code 

Lookup the organization (or ISP) for hostname. Use this method if you have an Organization/ISP database.

Parameters:
  • hostname (str) - Hostname
Returns: str
Organization or ISP name

record_by_addr(self, addr)

source code 

Look up the record for a given IP address. Use this method if you have a City database.

Parameters:
  • addr (str) - IP address
Returns: dict
Dictionary with country_code, country_code3, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_name, time_zone

record_by_name(self, hostname)

source code 

Look up the record for a given hostname. Use this method if you have a City database.

Parameters:
  • hostname (str) - Hostname
Returns: dict
Dictionary with country_code, country_code3, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_name, time_zone

region_by_addr(self, addr)

source code 

Lookup the region for given IP address. Use this method if you have a Region database.

Parameters:
  • addr (str) - IP address
Returns: dict
Dictionary containing country_code, region and region_name

region_by_name(self, hostname)

source code 

Lookup the region for given hostname. Use this method if you have a Region database.

Parameters:
  • hostname (str) - Hostname
Returns: dict
Dictionary containing country_code, region, and region_name

time_zone_by_addr(self, addr)

source code 

Look up the time zone for a given IP address. Use this method if you have a Region or City database.

Parameters:
  • addr (str) - IP address
Returns: str
Time zone

time_zone_by_name(self, hostname)

source code 

Look up the time zone for a given hostname. Use this method if you have a Region or City database.

Parameters:
  • hostname (str) - Hostname
Returns: str
Time zone