DeaD_EyE

ip_gen with start ip and end ip

May 11th, 2020
1,052
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ipaddress import ip_address, summarize_address_range
  2.  
  3.  
  4. def ip_gen(*start_end):
  5.     for addrs in start_end:
  6.         start, end = map(ip_address, addrs)
  7.         for subnet in summarize_address_range(start, end):
  8.             yield from subnet.hosts()
  9.  
  10.  
  11. A = ("10.0.0.0", "10.255.255.255")
  12. B = ("172.16.0.0", "172.31.255.255")
  13. C = ("192.168.0.0", "192.168.255.255")
  14. gen = ip_gen(A, B, C)
  15. ips = list(gen)
  16.  
  17. print(len(ips))
  18.  
  19. # 17891322
RAW Paste Data