forked from itdoginfo/allow-domains
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
executable file
·133 lines (103 loc) · 4.94 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
#!/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, 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}-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)
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 -= {f"*{domains}" for domains in removeDomains}
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')
if __name__ == '__main__':
# Russia inside
Path("Russia").mkdir(parents=True, exist_ok=True)
removeDomains = {'google.com', 'github.com', 'microsoft.com'}
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, removeDomains)
clashx(inside_lists, rusDomainsInsideOut, removeDomains)
kvas(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)
# 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)