DeaD_EyE

ipv6 subnetting

Jun 3rd, 2020
1,029
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ipaddress
  2.  
  3.  
  4. def ip_struct(network, dimensions, level=0):
  5.     if not dimensions:
  6.         return
  7.     level += 1
  8.     for subnet in network.subnets(dimensions[0]):
  9.         yield level, subnet
  10.         yield from ip_struct(subnet, dimensions[1:], level)
  11.  
  12.  
  13. def printer(gen):
  14.     for level, net in gen:
  15.         print(" " * level * 2 + f"{net!s}")
  16.  
  17.  
  18. net = ipaddress.IPv6Network('xxxx:xxxx:xxxx:xxxx::/64')
  19. printer(ip_struct(net, [2,2]))
RAW Paste Data