The Python script automatically updates the hosts to enable unlimited access to google

Source: Internet
Author: User
This article mainly introduces the Python script to automatically update hosts to achieve no-wall access to google. This article provides the implementation code directly. if you need it, you can refer to it and I believe many people still need to use google for search, however, the walls in China are getting worse and worse, and even vpn is being blocked. next we will give you a script to access 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'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-loopbackfe00: 0 ip6-localnetff00 :: 0 ip6-mcastprefixff02: 1 ip6-allnodesff0 2: 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.