Python script automatically updates the hosts implementation-free to turn over the wall to visit Google

Source: Internet
Author: User
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:

  • 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.