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

首頁 > 編程 > Python > 正文

python切換hosts文件代碼示例

2019-11-25 18:34:50
字體:
來源:轉載
供稿:網友

win7以上需要使用管理員權限操作。

復制代碼 代碼如下:

# -*- coding: utf-8 -*-
import os
import glob
import shutil

def format_file_list(files):
        all_files_str = ""
        for i in range(len(files)):
                all_files_str +=  str(i)+":"+files[i]+"/n"
        return all_files_str

hosts_path = "C://Windows//System32//drivers//etc"
files =  os.listdir(hosts_path)
os.chdir(hosts_path)

if os.getcwd() != hosts_path:
        print("Switch Dir to System32 Error,check permission!/npwd:"+os.getcwd())
        exit()

hosts_files = glob.glob("host*")
choosed_file_idx = int(input("Choose Hosts File Index:/n"+format_file_list(hosts_files)))
files_num = len(hosts_files)

if (choosed_file_idx < 0 or choosed_file_idx >= files_num) :
        print("Please choose a file in the lists!")
        exit()

print("Choosed idx:{0},file:{1}.".format(choosed_file_idx,hosts_files[choosed_file_idx]))
shutil.copy("hosts","hosts.bak")
shutil.copy(hosts_files[choosed_file_idx],"hosts")
print("Copy ok,then flush dns...")
os.system("ipconfig /flushdns")

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沅江市| 花莲县| 涟水县| 吉木乃县| 双桥区| 芒康县| 和政县| 惠东县| 嘉黎县| 云林县| 南通市| 郑州市| 九江县| 敖汉旗| 丰原市| 乃东县| 林口县| 和田市| 昌乐县| 汾西县| 县级市| 巴彦淖尔市| 上杭县| 马山县| 平泉县| 云安县| 余干县| 溆浦县| 新乡县| 延川县| 措勤县| 郓城县| 九江市| 庆城县| 蒙自县| 彰武县| 安义县| 镇坪县| 轮台县| 黎城县| 石阡县|