Linux下更新和备份Hosts

嗯嗯,啥也不说了。其实就是个从一些网站上获取最新Hosts。为了安全起见,需要以root权限运行。

貌似代码的缩进出现问题了。下载:http://forum.ubuntu.org.cn/download/file.php?id=167672

# coding=utf-8
import urllib
import os

def Download():
h=open('hosts','w')
fh=urllib.urlopen("https://smarthosts.googlecode.com/svn/trunk/hosts")
h.write(fh.read())
h.close

def Move():
Download()
os.system("mv /etc/hosts /etc/hosts.old")
os.system("mv hosts /etc/hosts")
print "更新完成,请重启浏览器"

def Rwnew():
os.system("mv etc/hosts.old /etc/hosts")
print "还原完成,请重启浏览器"

print "请以root权限运行"
print "请选择更新还是还原(1,更新;2,还原):"
i=int(input())

if i==1:
Move()
else:
if i==2:
Renew()
else:
print "EOF"

10条评论

  1. TheWorld Browser TheWorld Browser Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 TheWorld 6

    谢谢分享了,留言是美德,大家多留言

    1. Firefox 30.0 Firefox 30.0 Windows 8.1 x64 Edition Windows 8.1 x64 Edition
      Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0

      兔嫂好久不见啊

  2. Google Chrome 25.0.1364.97 Google Chrome 25.0.1364.97 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22

    好专业的,学习一下

  3. Google Chrome 26.0.1410.64 Google Chrome 26.0.1410.64 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31

    试了试,确实可行!

  4. Google Chrome 24.0.1312.57 Google Chrome 24.0.1312.57 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17

    不错,收藏了,谢谢博主分享

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注