```
#!/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
```