1
dphdjy 2016-05-19 09:29:41 +08:00 via Android
keyword: hosts2dns hosts2zone
|
2
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 ``` |
3
sahrechiiz OP @zyqf 谢谢
项目我 fork 了 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 |
4
zyqf 2016-05-19 21:23:29 +08:00
@sahrechiiz 比原来的完整, pull 过来呗
|
5
zyqf 2016-05-19 21:24:07 +08:00
@sahrechiiz 额,我自己改吧。。无视上条
|