本文整理汇总了Python中ipaddr.IPNetwork.iterhosts方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.iterhosts方法的具体用法?Python IPNetwork.iterhosts怎么用?Python IPNetwork.iterhosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.iterhosts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import iterhosts [as 别名]
def handle(self, *args, **options):
if len(args) == 0:
network, pattern = self.defaultnetwork, self.defaultpattern
if len(args) == 1:
network, pattern = IPNetwork(args[0]), self.defaultpattern
if len(args) == 2:
network, pattern = IPNetwork(args[0]), args[1]
for ip in network.iterhosts():
name = reverse(ip)
content = pattern % dict(
[(str(k), v) for k, v in enumerate(str(ip).split('.'))])
# print "%s\tcreated: %s" % (
# Record.objects.get_or_create(domain=self.get_domain(content),
# name=content, type='A', defaults={'content': str(ip)}))
print "%s\t\tcreated: %s" % (
Record.objects.get_or_create(domain=self.get_domain(name),
name=name, type='PTR', defaults={'content': content}))
示例2: IPAddress
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import iterhosts [as 别名]
# validate command-line options
try:
peer_ip = IPAddress(args.peer_ip)
except:
print 'invalid peer address "%s" - aborting' % args.peer_ip
sys.exit(1)
try:
local_cidr = IPNetwork(args.local_cidr)
except:
print 'invalid local addresses block "%s" - aborting' % args.local_cidr
sys.exit(1)
if args.announce_cidr:
try:
announce_cidr = IPNetwork(args.announce_cidr)
announce_cidr = announce_cidr.iterhosts()
except:
print 'invalid announce addresses block %s - aborting' % args.announce_cidr
sys.exit(1)
# create ExaBGP configuration + setup address aliases if required
configuration = 'group peers {\n'
sessions = 0
for address in local_cidr.iterhosts():
configuration += (' neighbor %s {\n'
' router-id %s;\n'
' local-address %s;\n'
' local-as %s;\n'
' peer-as %s;\n'
' family {\n'
' inet4 unicast;\n'