Created
January 4, 2019 16:01
-
-
Save matteyeux/020c46520b38d1a04a7ff4ad95115eee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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