-
Notifications
You must be signed in to change notification settings - Fork 76
/
convert.py
executable file
·180 lines (140 loc) · 7.25 KB
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/python3.10
import tldextract
import urllib.request
import re
from pathlib import Path
rusDomainsInsideSrc='src/Russia-domains-inside.lst'
rusDomainsInsideOut='Russia/inside'
rusDomainsInsideSrcSingle='src/Russia-domains-inside-single.lst'
rusDomainsOutsideSrc='src/Russia-domains-outside.lst'
rusDomainsOutsideOut='Russia/outside'
uaDomainsSrc='src/Ukraine-domains-inside.lst'
uaDomainsOut='Ukraine/inside'
def raw(src, out):
domains_raw = set()
for f in src:
with open(f) as infile:
for line in infile:
if tldextract.extract(line).suffix:
domains_raw.add(line.rstrip())
domains_raw = sorted(domains_raw)
with open(f'{out}-raw.lst', 'w') as file:
for name in domains_raw:
file.write(f'{name}\n')
def dnsmasq(src, out, single=None, remove={'google.com'}):
domains = set()
domains_single = set()
for f in src:
with open(f) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains.add(tldextract.extract(line.rstrip()).registered_domain)
if not tldextract.extract(line).domain and tldextract.extract(line).suffix:
domains.add("." + tldextract.extract(line.rstrip()).suffix)
if single is not None:
with open(single) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains_single.add(tldextract.extract(line.rstrip()).fqdn)
domains = domains.union(domains_single)
domains = domains - remove
domains = sorted(domains)
with open(f'{out}-dnsmasq-nfset.lst', 'w') as file:
for name in domains:
file.write(f'nftset=/{name}/4#inet#fw4#vpn_domains\n')
with open(f'{out}-dnsmasq-ipset.lst', 'w') as file:
for name in domains:
file.write(f'ipset=/{name}/vpn_domains\n')
def clashx(src, out, remove={'google.com'}):
domains = set()
for f in src:
with open(f) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains.add(tldextract.extract(line.rstrip()).registered_domain)
if not tldextract.extract(line).domain and tldextract.extract(line).suffix:
domains.add("." + tldextract.extract(line.rstrip()).suffix)
domains = domains - remove
domains = sorted(domains)
with open(f'{out}-clashx.lst', 'w') as file:
for name in domains:
file.write(f'DOMAIN-SUFFIX,{name}\n')
def kvas(src, out, single=None, remove={'google.com'}):
domains = set()
domains_single = set()
for f in src:
with open(f) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains.add("*" + tldextract.extract(line.rstrip()).registered_domain)
if not tldextract.extract(line).domain and tldextract.extract(line).suffix:
domains.add("*." + tldextract.extract(line.rstrip()).suffix)
domains -= {f"*{domains}" for domains in removeDomainsKvas}
if single is not None:
with open(single) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains_single.add(tldextract.extract(line.rstrip()).fqdn)
domains = domains.union(domains_single)
domains = sorted(domains)
with open(f'{out}-kvas.lst', 'w') as file:
for name in domains:
file.write(f'{name}\n')
def mikrotik_fwd(src, out, single=None, remove={'google.com'}):
domains = set()
domains_single = set()
for f in src:
with open(f) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains.add(tldextract.extract(line.rstrip()).registered_domain)
if not tldextract.extract(line).domain and tldextract.extract(line).suffix:
domains.add("." + tldextract.extract(line.rstrip()).suffix)
domains = domains - remove
if single is not None:
with open(single) as infile:
for line in infile:
if tldextract.extract(line).suffix:
if re.search(r'[^а-я\-]', tldextract.extract(line).domain):
domains_single.add(tldextract.extract(line.rstrip()).fqdn)
#domains = domains.union(domains_single)
domains = sorted(domains)
with open(f'{out}-mikrotik-fwd.lst', 'w') as file:
for name in domains:
file.write(f'/ip dns static add name={name} type=FWD address-list=allow-domains match-subdomain=yes forward-to=localhost\n')
for name in domains_single:
file.write(f'/ip dns static add name={name} type=FWD address-list=allow-domains match-subdomain=no forward-to=localhost\n')
if __name__ == '__main__':
# Russia inside
Path("Russia").mkdir(parents=True, exist_ok=True)
removeDomains = {'google.com', 'googletagmanager.com', 'github.com', 'githubusercontent.com', 'githubcopilot.com', 'microsoft.com', 'cloudflare-dns.com', 'parsec.app' }
removeDomainsKvas = {'google.com', 'googletagmanager.com', 'github.com', 'githubusercontent.com', 'githubcopilot.com', 'microsoft.com', 'cloudflare-dns.com', 'parsec.app', 't.co' }
urllib.request.urlretrieve("https://community.antifilter.download/list/domains.lst", "antifilter-domains.lst")
inside_lists = ['antifilter-domains.lst', rusDomainsInsideSrc]
raw(inside_lists, rusDomainsInsideOut)
dnsmasq(inside_lists, rusDomainsInsideOut, rusDomainsInsideSrcSingle, removeDomains)
clashx(inside_lists, rusDomainsInsideOut, removeDomains)
kvas(inside_lists, rusDomainsInsideOut, rusDomainsInsideSrcSingle, removeDomainsKvas)
mikrotik_fwd(inside_lists, rusDomainsInsideOut, rusDomainsInsideSrcSingle, removeDomains)
# Russia outside
outside_lists = [rusDomainsOutsideSrc]
raw(outside_lists, rusDomainsOutsideOut)
dnsmasq(outside_lists, rusDomainsOutsideOut)
clashx(outside_lists, rusDomainsOutsideOut)
kvas(outside_lists, rusDomainsOutsideOut)
mikrotik_fwd(outside_lists, rusDomainsOutsideOut)
# Ukraine
Path("Ukraine").mkdir(parents=True, exist_ok=True)
urllib.request.urlretrieve("https://uablacklist.net/domains.txt", "uablacklist-domains.lst")
urllib.request.urlretrieve("https://raw.githubusercontent.com/zhovner/zaborona_help/master/config/domainsdb.txt", "zaboronahelp-domains.lst")
ua_lists = ['uablacklist-domains.lst', 'zaboronahelp-domains.lst', uaDomainsSrc]
dnsmasq(ua_lists, uaDomainsOut)
clashx(ua_lists, uaDomainsOut)
kvas(ua_lists, uaDomainsOut)
mikrotik_fwd(ua_lists, uaDomainsOut)