相信还是有很多人需要使用google来进行搜索,但国内这墙也封得越来越厉害了,连vpn都开始被封了,下面给大家个不用翻墙就可以访问google的脚本.

脚本内容:

vi google_update.py

#!/usr/bin/env python
# coding: utf-8
# Author : toddlerya
# Date: Jan 18 2015
import urllib2
import re
import sys
import os
url = \"http://www.360kb.com/kb/2_122.html\"
req = urllib2.Request(url)
html = urllib2.urlopen(req).read()
head_ver = html.find(r\'google hosts \')
ver_before = len(\"google hosts \")
tail_ver = html.find(r\' 更新\')

head_span = html.find(\'#base services\')
tail_span = html.find(\'#google source end\')
raw_hosts = html[head_span:tail_span]
result, number = re.subn(r\'<.*>\', \'\', raw_hosts)
pure_hosts, number = re.subn(r\' \', \' \', result)
arch = \"\"\"127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1   ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
\"\"\"
print \"Update your host file start!\"
#print \"Please input your su password\"
f = file(r\'/tmp/hosts\' ,\'w+\')
new_host = [arch,pure_hosts]
f.writelines(new_host)
f.close()
os.system(\'mv /tmp/hosts /etc/hosts\')
print \"Update success!\"

结果如下图: