国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

解決谷歌搜索技術文章時打不開網頁問題的python腳本

2019-11-25 18:41:17
字體:
來源:轉載
供稿:網友
注意:Win7或者WIn8用戶要用管理員權限執行。

項目地址:http://code.google.com/p/my-hosts-file/downloads

復制代碼 代碼如下:

import urllib 
    import os 
    import shutil 

    hostspath = "C://Windows//System32//drivers//etc" 
    savepath = hostspath + "http://hostsave" 

    def download_hosts(url = "http://my-hosts-file.googlecode.com/svn/trunk/hosts"): 
        os.chdir(hostspath) 
        if os.getcwd() != hostspath: 
            print("Switch Dir to System32 Error,check permission!/npwd:"+os.getcwd()) 
            exit()  
        try: 
            urllib.urlretrieve(url, "hostsave") 
        except: 
            print '/t 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()
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中方县| 凭祥市| 崇义县| 勐海县| 沙河市| 宜黄县| 定边县| 扎赉特旗| 绍兴县| 息烽县| 林口县| 麟游县| 深水埗区| 泗阳县| 南充市| 兰州市| 华安县| 岢岚县| 阿图什市| 栾城县| 邵东县| 三门峡市| 中牟县| 九江县| 宁安市| 巫溪县| 凌海市| 周宁县| 大港区| 二手房| 泽普县| 甘德县| 阿拉善盟| 吴江市| 衡阳市| 孝感市| 河东区| 云浮市| 凤台县| 类乌齐县| 郯城县|