请问如何将 laod 发布的 hosts 文件转换成此项目的 rpz.zone?

2016-05-19 09:11:48 +08:00
 sahrechiiz

http://laod.cn/hosts/2016-google-hosts.html https://github.com/zyqf/DNS/blob/master-rpz/named/rpz.zone

3144 次点击
所在节点    DNS
5 条回复
dphdjy
2016-05-19 09:29:41 +08:00
keyword: hosts2dns hosts2zone
zyqf
2016-05-19 15:28:00 +08:00
```
#!/usr/bin/python
# -*- encoding: utf-8 -*-

import re
import urllib2

print 'fetching gfw hosts...'
url = 'https://github.com/racaljk/hosts/raw/master/hosts'
res = urllib2.urlopen(url).read()
lines = res.splitlines(True)

filename = 'rpz.zone'
conf = open(filename, 'w')
conf.write('# Dnsmasq Format\n\n\n')

ippat = re.compile('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
dmpat = re.compile('^[a-zA-Z\d-]{,63}(\.[a-zA-Z\d-]{,63})*$')

print 'parsing file...'
for line in lines:
line = line.strip()
if line.startswith('#'):
conf.write(line + "\n")
else:
if len(line) > 0:
if line.find('localhost') < 0 and line.find('255.255.255.255') < 0:
(ip, dm) = line.split()[:2]
if ippat.match(ip) and dmpat.match(dm):
conf.write(dm + ' IN A ' + ip + "\n")
else:
conf.write("\n")

conf.close()
print 'done, please use ' + filename
```
sahrechiiz
2016-05-19 17:41:33 +08:00
@zyqf 谢谢
项目我 fork 了 twitter 那段改了下
;twitter
twitter.com IN A 104.244.42.1
*.twitter.com IN A 104.244.42.3
www.twitter.com IN A 104.244.42.1
api.twitter.com IN A 104.244.42.2
mobile.twitter.com IN A 104.244.42.6
support.twitter.com IN A 104.244.42.7
upload.twitter.com IN A 104.244.42.11
tweetdeck.twitter.com IN A 104.244.42.132
tweetdeck.com IN A 104.244.42.132
*.tweetdeck.com IN A 104.244.42.132
syndication.twitter.com IN A 104.244.42.136
syndication-o.twitter.com IN A 104.244.42.136
cdn.syndication.twimg.com IN A 104.244.42.136
cdn.syndication.twitter.com IN A 104.244.42.136
cdn.api.twitter.com IN A 104.244.42.2
preview.cdn.twitter.com IN A 104.244.42.1
t.co IN A 104.244.42.197
*.t.co IN A 104.244.42.69
twitpic.com IN A 173.236.110.98
*.twitpic.com IN A 173.236.110.98
tinypic.com IN A 209.17.68.209
*.tinypic.com IN A 209.17.68.209
twimg.com IN A 104.244.43.199
*.twimg.com IN A 104.244.43.199
video.twimg.com IN A 104.244.43.199
zyqf
2016-05-19 21:23:29 +08:00
@sahrechiiz 比原来的完整, pull 过来呗
zyqf
2016-05-19 21:24:07 +08:00
@sahrechiiz 额,我自己改吧。。无视上条

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/279711

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX