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

Class GeoIP

source code

object --+
         |
        GeoIP

Nested Classes
  __metaclass__
Instance Methods
 
__init__(self, filename, flags=0, cache=True)
Initialize the class.
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

Inherited from object: __class__

Method Details

__init__(self, filename, flags=0, cache=True)
(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).
  • cache (bool) - Used in tests to skip instance caching
Overrides: object.__init__

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