Retrieve, store and query information about Regional Internet Registries
Project description
Retrieve, store and query information about Regional Internet Registries
Installation
pip install iprir
Usage
Query by ip:
>>> import iprir
>>> import iprir.database
>>> from ipaddress import IPv4Address, IPv6Address
>>> db = iprir.database.DB()
>>> db.by_ip(IPv4Address('8.8.8.8'))
RIRRecord(country='US', type='ipv4', start='8.0.0.0', value='16777216', status='allocated')
Attributes of RIRRecord
:
>>> record = db.by_ip(IPv4Address('8.8.8.8'))
>>> record.ipv4
IPv4Address('8.0.0.0')
>>> record.ipv4_network
IPv4Network('8.0.0.0/8')
>>> record.length
16777216
>>> record.as_int
134217728
Use IpSet:
>>> from iprir.ipset import IpSet
>>> us = IpSet.by_country('ipv4', 'US')
>>> IPv4Address('8.8.4.4') in us
True
>>> IPv4Address('1.2.3.4') in us
False
>>> us_and_ca_v6 = IpSet(db.by_country('ipv6', 'US') + db.by_country('ipv6', 'CA'))
>>> IPv6Address('2001:4860:4860::8888') in us_and_ca_v6
True
Update database:
# update text db and sqlite db
python3 -m iprir.updater
# show more choices
python3 -m iprir.updater -h
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iprir-0.2.1.dev0.tar.gz
(8.3 kB
view hashes)
Built Distribution
iprir-0.2.1.dev0-py3-none-any.whl
(17.0 MB
view hashes)
Close
Hashes for iprir-0.2.1.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a485fc5404ff496f05a8f2b8964675376dcc55decc2b2c6eb907c6f0a90e425a |
|
MD5 | a4c6955d232c7010e1dc17f1401a8080 |
|
BLAKE2b-256 | 241333b58b88b4dd78b27b7c15538d0e73a48b374df8fdbc82ecd070b9973201 |