Browse Source

came up with ipv6 generator

master
samialazar 2 years ago
parent
commit
ae989eeede
  1. 1
      sami/ipv6/.#randomnet.py
  2. 25
      sami/ipv6/randomnet.py
  3. 17
      sami/ipv6/test.py

1
sami/ipv6/.#randomnet.py

@ -0,0 +1 @@
sami@afro-linux-lenovo-b50-30.25798:1595421094

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

17
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))
Loading…
Cancel
Save