批量生成IPv6 subnet地址
Posted RegexL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量生成IPv6 subnet地址相关的知识,希望对你有一定的参考价值。
def get_ip(count=\'10\', start=\'2001:2:3:4:5:6:7:8\'): starts = start.split(\':\') A = int(starts[0], 16) # int(\'a\',16) 将字符串\'a\'进行16进制转换 base 存在时,视 x 为 base 类型数字,并将其转换为 10 进制数字。 # A2 = int(\'2001\', 16) # print(A2) B = int(starts[1], 16) # print(B) C = int(starts[2], 16) D = int(starts[3], 16) E = int(starts[4], 16) F = int(starts[5], 16) G = int(starts[6], 16) H = int(starts[7], 16) file = open(str(count)+\'_ipv6_Network_range_list.txt\', \'w\') for A in range(A, 65536): A = hex(A).replace(\'0x\', \'\') for B in range(B, 65536): B = hex(B).replace(\'0x\', \'\') for C in range(C, 65536): C = hex(C).replace(\'0x\', \'\') for D in range(D, 65536): D = hex(D).replace(\'0x\', \'\') for E in range(E, 65536): E = hex(E).replace(\'0x\', \'\') for F in range(F, 65536): F = hex(F).replace(\'0x\', \'\') for G in range(G, 65536): G = hex(G).replace(\'0x\', \'\') for H in range(50, 129): # print "H=",H H1 = hex(H).replace(\'0x\', \'\') H2 = hex(H+10).replace(\'0x\', \'\') ipv6 = "%s:%s:%s:%s:%s:%s:%s::/%s" % (A, B, C, D, E, F, G, H) if count > 1: file.write(ipv6 + "\\n") count -= 1 print(ipv6) elif count == 1: file.write(ipv6) count -= 1 else: file.close() return H = 0 G = 0 F = 0 E = 0 D = 0 C = 0 B = 0 if __name__ == \'__main__\': get_ip(100, \'2001:2:3:4:5:6:FFFE:FFFa\')
以上是关于批量生成IPv6 subnet地址的主要内容,如果未能解决你的问题,请参考以下文章
2019-05-30 Python+Jinja2+yaml 批量生成配置