diff --git a/sami/ipv6/.#randomnet.py b/sami/ipv6/.#randomnet.py new file mode 120000 index 0000000..fcbec7b --- /dev/null +++ b/sami/ipv6/.#randomnet.py @@ -0,0 +1 @@ +sami@afro-linux-lenovo-b50-30.25798:1595421094 \ No newline at end of file diff --git a/sami/ipv6/randomnet.py b/sami/ipv6/randomnet.py new file mode 100644 index 0000000..80a39ba --- /dev/null +++ b/sami/ipv6/randomnet.py @@ -0,0 +1,25 @@ +#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) diff --git a/sami/ipv6/test.py b/sami/ipv6/test.py new file mode 100644 index 0000000..208f7ad --- /dev/null +++ b/sami/ipv6/test.py @@ -0,0 +1,17 @@ +#import random +#from ipaddress import IPv6Network, IPv6Address + +#ip_a = IPv6Network('2001:db8::/48') + random.getrandbits +#ip_n = IPv6Network(ip_a) +#ip_n.prefixlen = 64 + +#print (ip_a) +#print (ip_n) + +from ipaddress import IPv6Network +import random + +ula = IPv6Network("fd00::/8") +random_network = IPv6Network(( + ula.network_address + (random.getrandbits(64 - ula.prefixlen) << 64 ), + 64))