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
_lookup_country_id(self, addr)
Get the country index.
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 converted IP addr.
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
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 the organization (or ISP) 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

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 the only supported flags are STANDARD, MEMORY_CACHE, and MMAP_CACHE.
Overrides: object.__init__

_lookup_country_id(self, addr)

source code 

Get the country index.

This method is called by the _lookupCountryCode and _lookupCountryName methods. It looks up the index ('id') 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

_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 converted IP addr.

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

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) - host name
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) - host name
Returns: str
country name

org_by_addr(self, addr)

source code 

Lookup the organization (or ISP) for given IP address. Use this method if you have an Organization/ISP 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) - host name
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
dict 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) - host name
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

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
dict 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) - host name
Returns: dict
dict containing country_code, region, and region_name