mirror of
https://bitbucket.org/anticensority/antizapret-pac-generator-light.git
synced 2024-11-22 13:16:04 +03:00
20 lines
727 B
Python
20 lines
727 B
Python
|
#!/usr/bin/env python3
|
||
|
import ipaddress
|
||
|
addrlist = open('result/iplist_blockedbyip_noid2971.txt', 'r').read()
|
||
|
speciallist = open('result/iplist_special_range.txt', 'r').read()
|
||
|
nlist = [ipaddress.IPv4Network(addr) for addr in addrlist.split()]
|
||
|
slist = [ipaddress.IPv4Network(addr) for addr in speciallist.split()]
|
||
|
print('IP Addresses before collapsing:', len(nlist))
|
||
|
|
||
|
for i, v in enumerate(nlist):
|
||
|
if any([addr.overlaps(v) for addr in slist]):
|
||
|
del nlist[i]
|
||
|
|
||
|
print('IP Addresses after removing special ranges:', len(nlist))
|
||
|
|
||
|
collapsed_file_prefix = open('result/iplist_blockedbyip_noid2971_collapsed.txt', 'w')
|
||
|
cnt = 0
|
||
|
for addr in nlist:
|
||
|
print(str(addr).replace('/32', ''), file=collapsed_file_prefix)
|
||
|
cnt+=1
|