Believe there are still a lot of people need to use Google to search, but the domestic wall is also more and more powerful, even the VPN is beginning to be sealed, the following for everyone can access Google's script without flipping the wall.
Script content:
VI google_update.py
#!/usr/bin/env python# coding:utf-8# author:toddlerya# date:jan 2015import urllib2import reimport sysimport osurl = "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 ' update ') 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 Lin ES is desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 Ip6-allnodesff02::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!"
Results such as: