admin管理员组

文章数量:1516870

注意:Win7或者WIn8用户要用管理员权限执行。

项目地址:

import urllib

import os

import shutil

hostspath = "C:\Windows\System32\drivers\etc"

savepath = hostspath + "\hostsave"

def download_hosts(url = ""):

os.chdir(hostspath)

if os.getcwd() != hostspath:

print("Switch Dir to System32 Error,check permission! pwd:"+os.getcwd())

exit()

try:

urllib.urlretrieve(url, "hostsave")

except:

print " Error when retrieveing hosts file from url: ", url

def backup_hosts():

shutil.copy("hosts","hosts.bak")

def replace_hosts():

shutil.copy("hostsave", "hosts")

print("Replace original hosts file finished, then flush dns...")

os.remove(savepath)

os.system("ipconfig /flushdns")

def main():

download_hosts()

backup_hosts()

replace_hosts()

if __name__ == "__main__":

main()

本文标签: 搞定难题快速修复