Created
May 2, 2018 13:11
-
-
Save hatarist/1347a4eb9283f985417721e604e1fdab to your computer and use it in GitHub Desktop.
I'm a lazy ass who didn't think it's worth to bother with the standard ipaddress library
This file contains hidden or 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
import random | |
import sys | |
from netaddr import IPNetwork, IPAddress | |
def generate_random_ipv6(subnet): | |
network = IPNetwork(subnet) | |
return str(IPAddress(random.randrange(network.first, network.last))) | |
if __name__ == '__main__': | |
if len(sys.argv) not in (2, 3): | |
print('Usage: python ipv6gen.py <subnet> <amount>') | |
print('Example:') | |
print(' python ipv6gen.py 4001:266:f088:1acd::1/64 15') | |
print(' (shows a list of 15 random IPs within the given subnet)') | |
sys.exit(1) | |
subnet = sys.argv[1] | |
amount = int(sys.argv[2]) if len(sys.argv) == 3 else 10 | |
for _ in range(amount): | |
print(generate_random_ipv6(subnet)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment