Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- ##################################
- # pip install netaddr
- from netaddr import IPAddress, IPNetwork
- file_out = "./internet-connected.csv"
- with open(file_out, mode='a+') as f:
- for class_a in range(0, 255):
- a = IPAddress("%s.0.0.0" % class_a)
- if not a.is_reserved():
- for class_b in range(0, 255):
- b = IPAddress("%d.%d.0.0" % (class_a, class_b))
- if not b.is_reserved():
- for class_c in range(0, 255):
- c = IPAddress("%d.%d.%d.0" % (class_a, class_b, class_c))
- if not c.is_reserved() and not c.is_private():
- ip = "%s/24" % c
- for host_ip in IPNetwork(ip).iter_hosts():
- if host_ip.is_unicast():
- f.write(str(host_ip) + '\n')
Add Comment
Please, Sign In to add comment