Python script automatically updates hosts to achieve wall-free access Google_python

Source: Internet
Author: User
Tags python script

Believe that there are a lot of people need to use Google to search, but the domestic wall is also more and more powerful, even the VPN has begun to be blocked, the following to everyone who 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 2015 import urllib2 import RE import sys Os url = "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 (' #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 "" " 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 succes

 S! "

The results are shown below:

Related Article

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.