获取云提供商netblocks
项目描述
Netblocks
这不是一个官方的Google产品。
此模块根据以下链接递归检索DNS条目
The GCE ranges
https://cloud.google.com/compute/docs/faq#where_can_i_find_product_name_short_ip_ranges
The Google Services ranges
https://support.google.com/a/answer/60764
The AWS ranges
https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html
使用 pip install netblocks
或 pip install git+https://github.com/hm-distro/netblocks/
安装包
fetch()
方法默认参数值为 initial_dns_list=[GOOGLE_INITIAL_CLOUD_NETBLOCK_DNS, GOOGLE_INITIAL_SPF_NETBLOCK_DNS]
其中
#The GCE ranges
GOOGLE_INITIAL_CLOUD_NETBLOCK_DNS = "_cloud-netblocks.googleusercontent.com"
#The Google Services ranges
GOOGLE_INITIAL_SPF_NETBLOCK_DNS= "_spf.google.com"
#The AWS ranges
AWS_IP_RANGES="https://ip-ranges.amazonaws.com/ip-ranges.json"
请在此处查看如何在使用Google App Engine中使用此模块这里
API使用
import netblocks
cidr_blocks = set()
api = netblocks.NetBlocks()
try:
# returns both GOOGLE_INITIAL_CLOUD_NETBLOCK_DNS and GOOGLE_INITIAL_SPF_NETBLOCK_DNS
cidr_blocks = api.fetch()
# To get only the SPF list use the below:
# cidr_blocks = api.fetch([netblocks.GOOGLE_INITIAL_SPF_NETBLOCK_DNS])
# To get only the GCE list use the below:
# cidr_blocks = api.fetch([netblocks.GOOGLE_INITIAL_CLOUD_NETBLOCK_DNS])
# To get only the AWS list use the below:
# cidr_blocks = api.fetch([netblocks.AWS_IP_RANGES])
"""
The cidr_blocks set contains strings like the below
ip4:146.148.2.0/23
...
ip6:2600:1900::/35
"""
except netblocks.NetBlockRetrievalException as err:
#exception handling
pass
语言
依赖
requests
许可证
Apache 2.0;有关详细信息,请参阅LICENSE