mirror of
https://bitbucket.org/anticensority/antizapret-pac-generator-light.git
synced 2024-11-27 07:36:03 +03:00
20 lines
727 B
Python
Executable File
20 lines
727 B
Python
Executable File
#!/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
|