如何使用 python3 将 CIDR 转换为 IP 范围?

tel*_*st1 8 python ip cidr python-3.x

如何转换列表,例如:

94.192.0.0/14  
94.0.0.0/12  
93.96.0.0/16 
Run Code Online (Sandbox Code Playgroud)

到:

94.192.0.0-94.195.255.255  
94.0.0.0-94.15.255.255  
93.96.0.0-93.96.255.255  
Run Code Online (Sandbox Code Playgroud)

使用python3?

ffe*_*rri 12

使用ipaddress内置模块:

>>> import ipaddress

>>> net=ipaddress.ip_network('94.192.0.0/14')
IPv4Network('94.192.0.0/14')

>>> '%s-%s' % (net[0], net[-1])
'94.192.0.0-94.195.255.255'
Run Code Online (Sandbox Code Playgroud)

 

您还for i in net可以枚举网络中的所有netIP 地址。