其他分享
首页 > 其他分享> > 批量生成IPv6 host地址

批量生成IPv6 host地址

作者:互联网

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_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(H, 65536):
                                    # print "H=",H
                                    H = hex(H).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')

  

标签:批量,16,int,starts,hex,replace,host,IPv6,65536
来源: https://www.cnblogs.com/liuwenpeng/p/14897215.html