Merge remote-tracking branch 'sami/master'
This commit is contained in:
commit
bb98d0c987
3 changed files with 43 additions and 0 deletions
1
sami/ipv6/.#randomnet.py
Symbolic link
1
sami/ipv6/.#randomnet.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
sami@afro-linux-lenovo-b50-30.25798:1595421094
|
25
sami/ipv6/randomnet.py
Normal file
25
sami/ipv6/randomnet.py
Normal file
|
@ -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
Normal file
17
sami/ipv6/test.py
Normal file
|
@ -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…
Reference in a new issue