aboutsummaryrefslogtreecommitdiffstats
path: root/bin/exclude_ip_list
blob: a4df77b8ceffde8d0df1fd1e7e09de1c7cf7a55b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
from ipaddress import ip_network

start = '0.0.0.0/0'
exclude = ['127.0.0.1', '192.168.1.0/24',
           '185.126.202.69', '87.236.209.206', '185.126.202.69',
           '94.182.18.223']

result = [ip_network(start)]
for x in exclude:
    n = ip_network(x)
    new = []
    for y in result:
        if y.overlaps(n):
            new.extend(y.address_exclude(n))
        else:
            new.append(y)
    result = new

print(','.join(str(x) for x in sorted(result)))