forked from zsokami/ACL4SSR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_hosts.py
70 lines (40 loc) · 1.39 KB
/
update_hosts.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
import os
import requests
session = requests.Session()
session.headers['X-Apikey'] = os.getenv('VIRUSTOTAL_API_KEY')
def subdomains(domain):
resp = session.get(f'https://www.virustotal.com/api/v3/domains/{domain}/subdomains?limit=1000')
if not resp.ok:
raise Exception(resp.status_code, resp.text)
return [x['id'] for x in resp.json()['data'] if 'attributes' in x and any(
r['type'][0] == 'A' for r in x['attributes']['last_dns_records'])]
def sub(domain, fn=None):
return '\n'.join(f'0.0.0.0 {x}' for x in subdomains(domain) if not fn or fn(x))
hosts = f'''127.0.0.1 localhost
::1 ip6-localhost
# 扩展 APP 广告拦截规则,对某些影视/动漫 APP 有加速奇效
{sub('sigmob.cn')}
{sub('ugdtimg.com')}
0.0.0.0 open.e.kuaishou.com
0.0.0.0 open.e.kuaishou.cn
{sub('adkwai.com')}
{sub('adukwai.com')}
{sub('e.qq.com')}
{sub('gdt.qq.com')}
0.0.0.0 gray.i.gdt.qq.com
0.0.0.0 q.i.gdt.qq.com
0.0.0.0 gray.v.gdt.qq.com
{sub('pangolin-sdk-toutiao.com')}
{sub('pangolin-sdk-toutiao-b.com')}
0.0.0.0 api-access.pangolin-sdk-toutiao1.com
{sub('snssdk.com', lambda x: x.startswith(('pangolin', 'tnc')))}
{sub('pglstatp-toutiao.com')}
{sub('ctobsnssdk.com')}
0.0.0.0 api.hzsanjiaomao.com
0.0.0.0 api.juliangcili.com
{sub('anythinktech.com')}
0.0.0.0 utoken.umeng.com
0.0.0.0 ulogs.umeng.com
'''
with open('hosts', 'w') as f:
f.write(hosts)