Skip to content

Instantly share code, notes, and snippets.

@tlhc
Created November 2, 2013 11:20
Show Gist options
  • Save tlhc/7277899 to your computer and use it in GitHub Desktop.
Save tlhc/7277899 to your computer and use it in GitHub Desktop.
get the google dns list
# !/usr/bin/env python
#my first python script
import urllib2
import os
enable_proxy = True
proxy_hander = urllib2.ProxyHandler({"http" : 'http://127.0.0.1:8087'})
null_proxy_hander = urllib2.ProxyHandler({})
if enable_proxy:
opener = urllib2.build_opener(proxy_hander)
else:
opener = urllib2.build_opener(null_proxy_hander)
#urllib2.install_opener(opener)
content = opener.open('https://smarthosts.googlecode.com/svn/trunk/hosts_us').read()
f = open('data.txt', 'w')
f.write(content)
f.close()
rest = list()
f = open('data.txt', 'r')
for line in f.readlines():
line = line.strip()
rest.append(line)
f.close()
start = rest.index("#SmartHosts START")
end = rest.index("#SmartHosts END")
f = open('data_fiter.txt', 'w')
while start <= end:
f.writelines(rest[start])
f.write("\n")
start += 1
f.close()
#clean
os.remove('data.txt')
os.rename('data_fiter.txt', 'hosts_us')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment