本文整理汇总了Python中netaddr.IPNetwork.is_private方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.is_private方法的具体用法?Python IPNetwork.is_private怎么用?Python IPNetwork.is_private使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.is_private方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import is_private [as 别名]
def add(caller_id, address, mask):
networks = []
for net in AvailableNetwork.objects.all():
networks.append(net.to_ipnetwork())
networks.sort()
# Find duplicate
ipnet = IPNetwork('%s/%d' % (address, mask))
for i in xrange(len(networks)):
if ipnet.prefixlen > networks[i].prefixlen and ipnet > networks[i].previous() and ipnet < networks[i].next():
raise CMException('network_exists')
elif ipnet.prefixlen < networks[i].prefixlen and ipnet.previous() < networks[i] and ipnet.next() > networks[i]:
raise CMException('network_exists')
# Add new network
new_net = AvailableNetwork()
new_net.address = ipnet.network
new_net.mask = mask
if ipnet.is_private():
new_net.state = available_network_states['ok']
else:
new_net.state = available_network_states['locked']
new_net.save()