| | |
- addressblock
- iptocountry
class addressblock |
| |
Representation of an address block. |
| |
Methods defined here:
- __eq__(self, other)
- if compared with a string, then assume string is an ip-address, and
check if this ip is in the addressblock that the object represents
- __init__(self, start_dec, end_dec, cc_tld)
- __len__(self)
- Returns the length of the address block, ie. how many IP-addresses
it contains.
- __str__(self)
- ip_end(self)
- Returns the last IP-address in the address-block.
- ip_start(self)
- Returns the first IP-address in the address-block.
|
class iptocountry |
| |
An interface to work with the ip-to-country database.
It does loading of the database from the web, and caches it in a
pickle'd file.
After this, the database can be queried either by address,
or by country. |
| |
Methods defined here:
- __init__(self, download_dir=None)
- Constructor, download_dir can be used to specify where to
cache the database from the web.
- find_by_addr(self, ip_addr)
- Find the block which the ip_addr IP-address belongs to. Returns
None if it is not found.
- find_by_country(self, cc_tld)
- Find all the address block which belong to a country code TLD.
cc_tld is the country code TLD, eg. 'dk' for Denmark, or 'us' for
USA.
- initialize(self, new_url=None)
- Downloads the database from the web, and process it into
a pickle'd file. new_url is an alternative URL where to load
the file from.
Data and other attributes defined here:
- IP2C_CSV = 'ip-to-country.csv'
- IP2C_URL = 'http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip'
- PICKLE_FILE = 'ip-to-country.pkl'
| |