Last active
September 6, 2018 09:22
-
-
Save jjsantanna/accaa34d29cf060a4448bac4f5fb70be to your computer and use it in GitHub Desktop.
Generate a wildcard of \24 IP ranges from a IP range < 24
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 IPv4Network | |
def iprange2range24wildcard(iprange): | |
if(int(str(iprange).split('/')[1])) <= 24 : | |
slash24networks=[] | |
for e in list(IPv4Network(iprange).subnets(new_prefix=24)): | |
slash24networks.append(str(e).replace('0/24', '%')) | |
return slash24networks | |
else: | |
print ('ERROR: The subnetwork MUST be less or equal than /24.') | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment