def increment_ipv6(ipv6):
parts = ipv6.split(':')
for i in range(len(parts) - 1, -1, -1):
if parts[i] == '':
parts[i] = '0'
parts[i] = f'{int(parts[i], 16) + 1:04x}'
if int(parts[i], 16) <= 0xffff:
break
parts[i] = '0000'
return ':'.join(parts)
def generate_sequential_ipv6(start_ipv6, count):
current_ipv6 = start_ipv6
for _ in range(count):
yield current_ipv6
current_ipv6 = increment_ipv6(current_ipv6)
# 从指定的IPv6地址开始生成10个顺序IPv6地址,并将其保存在一个txt文件里
start_ipv6 = '2001:f8c0:56f2:2e13:0000:0000:0000:0001'
count = 10
with open('ipv6_addresses.txt', 'w') as file:
for ipv6 in generate_sequential_ipv6(start_ipv6, count):
file.write(ipv6 + '\n')
print("The IPv6 addresses have been successfully saved to ipv6_addresses.txt")