检索、存储和查询有关区域互联网注册中心的信息
iprir的Python项目详细描述
检索、存储和查询有关地区互联网注册中心的信息
安装
pip install iprir
用法
按IP查询:
>>>importiprir>>>fromipaddressimportIPv4Address,IPv6Address>>>iprir.by_ip(IPv4Address('8.8.8.8'))RIRRecord(country='US',type='ipv4',start='8.0.0.0',value='16777216',status='allocated')
属性RIRRecord
:
>>>record=iprir.by_ip(IPv4Address('8.8.8.8'))>>>record.ipv4IPv4Address('8.0.0.0')>>>record.ipv4_networkIPv4Network('8.0.0.0/8')>>>record.length16777216>>>record.as_int134217728
使用ipset:
>>>us=iprir.by_country('ipv4','US')>>>IPv4Address('8.8.4.4')inusTrue>>>IPv4Address('1.2.3.4')inusFalse>>>fromiprir.ipsetimportIpSet>>>db=iprir.get_db()>>>us_and_ca_v6=IpSet(db.by_country('ipv6','US')+db.by_country('ipv6','CA'))>>>IPv6Address('2001:4860:4860::8888')inus_and_ca_v6True
更新数据库:
# update text db and sqlite db python3 -m iprir.updater # show more choices python3 -m iprir.updater -h