Skip to content

Commit 8f17250

Browse files
authored
Add files via upload
1 parent 5e09127 commit 8f17250

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

host_trans_anti.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#UTF-8
2+
3+
#把anti-AD的dsnmasq转换成MelinClash的hosts格式
4+
5+
import wget
6+
from datetime import date
7+
today = date.today()
8+
9+
def host_trans(url):
10+
file = wget.download(url, out='/home/lambda/Documents/adblock/anti_ad_'+str(today)+'.conf')
11+
with open(file, 'r') as f:
12+
new_f = open('/home/lambda/Documents/adblock/anti_ad_'+str(today)+'.yaml', 'w')
13+
new_f.write('hosts:\n')
14+
new_f.write(' router.asus.com: 192.168.50.1\n')
15+
new_f.write(' services.googleapis.cn: 74.125.193.94\n')
16+
for lines in f:
17+
if '#' not in lines and not lines == "\n":
18+
# 获取网址
19+
tail = lines[9:].strip()
20+
# tail[:-1] 去掉字符串尾部的 /
21+
new_lines = " " + tail[:-1] + ": " + '127.0.0.1'
22+
new_f.write(new_lines+'\n')
23+
else:
24+
pass
25+
new_f.close()
26+
print("anti-ad.yaml文件保存在文档/adblock文件夹下")
27+
28+
if __name__ == '__main__':
29+
url = 'https://anti-ad.net/anti-ad-for-dnsmasq.conf'
30+
host_trans(url)

0 commit comments

Comments
 (0)