tg_generators.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:taf 作者: taf3 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号