def __next__(self):
"""Get next generated IPv6 address.
"""
current = self.value
if self.iterator >= self.count and self.count != 0:
self.value = self.start_value
self.iterator = 1
else:
ip = ipaddr.IPv6Address(self.value)
try:
hex_ip = hex(int(ip))
part_hex_lo = hex_ip[-8:]
part_hex_hi = hex_ip[0:-8]
int_hex_lo = int(part_hex_lo, 16)
int_lo = int_hex_lo + self.increment
if int_lo > int("FFFFFFFF", 16):
diff = int_lo - int("FFFFFFFF", 16)
int_lo = int("00000000", 16) + diff
if int_lo < int("00000000", 16):
diff = int_lo - int("00000000", 16)
int_lo = int("FFFFFFFF", 16) + diff
part_hex_lo = hex(int_lo)[2:]
new_ip_hex = part_hex_hi + part_hex_lo.zfill(8)
ip = ipaddr.IPv6Address(int(new_ip_hex, 16))
self.value = str(ip)
except ipaddr.AddressValueError:
self.value = self.start_value
self.iterator += 1
return current
评论列表
文章目录