25 lines
551 B
Python
25 lines
551 B
Python
#import random
|
|
#from netaddr.ip import IPNetwork, IPAddress
|
|
#import string
|
|
#random.seed()
|
|
#ip_a = IPAddress('2001::cafe:0') + random.getrandbits(16)
|
|
#ip_n = IPNetwork(ip_a)
|
|
#ip_n.prefixlen = 64
|
|
|
|
#print (ip_a)
|
|
#print (ip_n)
|
|
|
|
"""
|
|
Generate a random IPv6 address for a specified subnet
|
|
"""
|
|
|
|
from random import seed, getrandbits
|
|
from ipaddress import IPv6Network, IPv6Address
|
|
|
|
subnet = 'fd00::/8'
|
|
|
|
seed()
|
|
network = IPv6Network(subnet)
|
|
address = IPv6Address(network.network_address + getrandbits(network.max_prefixlen - network.prefixlen))
|
|
|
|
print(address)
|