Skip to content

Instantly share code, notes, and snippets.

@nix1947
Forked from hatarist/ipv6gen.py
Created June 8, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nix1947/3cf9d4d89be61a2f80255614275f2f1c to your computer and use it in GitHub Desktop.
Save nix1947/3cf9d4d89be61a2f80255614275f2f1c 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
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