-
-
Save limkokhole/953f7a592639f0818194d7c0bf21aafa to your computer and use it in GitHub Desktop.
Generate a random IPv6 address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Generate a random IPv6 address for a specified subnet | |
""" | |
from random import seed, getrandbits | |
from ipaddress import IPv6Network, IPv6Address | |
subnet = '2001:db8:100::/64' | |
seed() | |
network = IPv6Network(subnet) | |
address = IPv6Address(network.network_address + getrandbits(network.max_prefixlen - network.prefixlen)) | |
print(address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment