-
-
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
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