The Python script automatically updates the hosts to enable the firewall-free access to google,
I believe there are still many people who need to use google for search, but the domestic wall is getting worse and worse, and even vpn is being blocked, the following is a script for accessing google without turning over the wall.
Script content:
Vi google_update.py
#! /Usr/bin/env python # coding: UTF-8 # Author: toddlerya # Date: Jan 18 2015 import 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' <strong> google hosts </strong> <strong> ') ver_before = len ("<strong> google hosts </strong> <strong> ") tail_ver = html. find (R' </strong> Update') head_span = html. find ('# ba Se 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-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!"
The result is as follows: