#!/usr/bin/env python3 import ipaddress ips = [ipaddress.ip_network('0.0.0.0/0')] exts = map(ipaddress.ip_network,ยท ''' 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 127.0.0.0/8 '''.strip().splitlines()) def negate(ips, negate_ip): new_ips = [] for ip in ips: new_ips += list(ip.address_exclude(negate_ip)) if ip.overlaps(ext) else [ip] return new_ips for ext in exts: ips = negate(ips, ext) for ip in ips: print(ip)