- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhost_trans_anti.py
More file actions
Latest commit
30 lines (26 loc) · 1.04 KB
/
Copy pathhost_trans_anti.py
File metadata and controls
30 lines (26 loc) · 1.04 KB
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
#UTF-8
#把anti-AD的dsnmasq转换成MelinClash的hosts格式
importwget
fromdatetimeimportdate
today=date.today()
defhost_trans(url):
file=wget.download(url, out='/home/lambda/Documents/adblock/anti_ad_'+str(today)+'.conf')
withopen(file, 'r') asf:
new_f=open('/home/lambda/Documents/adblock/anti_ad_'+str(today)+'.yaml', 'w')
new_f.write('hosts:\n')
new_f.write(' router.asus.com: 192.168.50.1\n')
new_f.write(' services.googleapis.cn: 74.125.193.94\n')
forlinesinf:
if'#'notinlinesandnotlines=="\n":
# 获取网址
tail=lines[9:].strip()
# tail[:-1] 去掉字符串尾部的 /
new_lines=" "+tail[:-1] +": "+'127.0.0.1'
new_f.write(new_lines+'\n')
else:
pass
new_f.close()
print("anti-ad.yaml文件保存在文档/adblock文件夹下")
if__name__=='__main__':
url='https://anti-ad.net/anti-ad-for-dnsmasq.conf'
host_trans(url)