Merge remote-tracking branch 'youngjin/master' into master
This commit is contained in:
commit
9501d81d30
3 changed files with 83 additions and 0 deletions
|
@ -1,3 +1,6 @@
|
|||
* 2020-07-24
|
||||
** note
|
||||
- none
|
||||
* 2020-07-22
|
||||
** note
|
||||
- none
|
||||
|
|
59
youngjin.han/ipv6/source/randomnet.py
Normal file
59
youngjin.han/ipv6/source/randomnet.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# from sys import argv
|
||||
import argparse
|
||||
import ipaddress
|
||||
import random
|
||||
|
||||
# script, prefix = argv
|
||||
|
||||
def main(ipv6net_list, size_list):
|
||||
"""
|
||||
메인 함수
|
||||
"""
|
||||
if 2 == len(ipv6net_list):
|
||||
ipv6net_src = ipaddress.IPv6Interface(ipv6net_list[0])
|
||||
size = ipv6net_list[1]
|
||||
print('Input : {}'.format(ipv6net_src))
|
||||
print('Size : {}'.format(size))
|
||||
elif 2 > len(ipv6net_list):
|
||||
ipv6net_src = ipaddress.IPv6Interface(ipv6net_list[0])
|
||||
size = size_list
|
||||
print('Input : {}'.format(ipv6net_list))
|
||||
print('Size : {}'.format(size))
|
||||
else:
|
||||
ipv6net_src = []
|
||||
size = size_list
|
||||
print('Please, Read Help')
|
||||
|
||||
ipv6_rand = 0
|
||||
size_rand = int(size)-int(str(ipv6net_src)[str(ipv6net_src).find('/')+1:])
|
||||
while size_rand != 0:
|
||||
if 16 <= size_rand:
|
||||
ipv6_rand = ipv6_rand << 16
|
||||
ipv6_rand += random.randint(0, (2**16)-1)
|
||||
size_rand -= 16
|
||||
else:
|
||||
ipv6_rand = ipv6_rand << size_rand
|
||||
ipv6_rand += random.randint(0, (2**size_rand)-1)
|
||||
size_rand = 0
|
||||
|
||||
# print('{}'.format(ipaddress.IPv6Network((ipv6net_src))))
|
||||
# print('{}'.format(str(ipaddress.IPv6Address((ipv6_rand<<(128-int(size)))))+'/'+size))
|
||||
# print('{}'.format(int(size)-int(str(ipv6net_src)[str(ipv6net_src).find('/')+1:])))
|
||||
print('Output : {}'.format(str(ipaddress.IPv6Address(int(ipv6net_src)+(ipv6_rand <<(128 - int(size)))))+'/'+size))
|
||||
|
||||
def get_arguments():
|
||||
"""
|
||||
argument를 파싱해서 가져옴
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('ipv6net', nargs='+', help='Example) 2001:db8::/40 or 2001:db8::/40 64', type=str)
|
||||
parser.add_argument('--size', nargs='?', help='Example) 64...0', default='48', type=str)
|
||||
|
||||
ipv6net_list = parser.parse_args().ipv6net
|
||||
size_list = parser.parse_args().size
|
||||
|
||||
return ipv6net_list, size_list
|
||||
|
||||
if __name__ == '__main__':
|
||||
ipv6net_list, size_list = get_arguments()
|
||||
main(ipv6net_list, size_list)
|
|
@ -1,3 +1,24 @@
|
|||
* 2020-07-24
|
||||
*** IPv6 #2: Generating IPv6 networks
|
||||
**** DONE Lecture content
|
||||
CLOSED: [2020-07-30 목 00:43]
|
||||
- Objective/Problem that we are trying to solve:
|
||||
- You got one bigger prefix (the one that you get as a
|
||||
parameter) and you want to create a random subnetwork in it
|
||||
- Create a random /48 network within a prefix
|
||||
- Create a python script named *randomnet.py* that accepts 1
|
||||
parameter: *prefix*
|
||||
- The prefix must be an IPv6 network
|
||||
- The netmask of the prefix should be /48 or smaller (/48.../0)
|
||||
- Prefixes to be used for testing:
|
||||
- 2001:db8::/48
|
||||
- 2001:db8::/40
|
||||
- 2001:db8::/32
|
||||
- fd00::/8
|
||||
- Possible output:
|
||||
- 2001:db8:1231::/48
|
||||
- Optional
|
||||
- Allow to specify second parameter that gives the size of the subnetwork
|
||||
* 2020-07-22
|
||||
*** IPv6 #1: IPv6 address uniqueness
|
||||
**** DONE Lecture content
|
||||
|
|
Loading…
Reference in a new issue