Skip to content

Instantly share code, notes, and snippets.

@matteyeux
Created January 4, 2019 16:01
Show Gist options
  • Save matteyeux/020c46520b38d1a04a7ff4ad95115eee to your computer and use it in GitHub Desktop.
Save matteyeux/020c46520b38d1a04a7ff4ad95115eee to your computer and use it in GitHub Desktop.
from ipaddress import *
ip, mask = '192.168.9.5', '255.255.255.0'
cidr = 24
host, net = IPv4Address(ip), IPv4Network(ip + '/' + mask, False)
sub = IPv4Address(int(host) & int(net.netmask))
sub_and_cidr = '{0}/{1}'.format(sub, cidr)
ips = ip_network(sub_and_cidr).hosts()
with open('ip.txt', 'w') as f:
for i in list(ips):
f.write(str(i) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment