python修改hosts

#coding=utf-8


host = ['192.168.10.240 store.wondershare.com',
        '192.168.10.240 store.wondershare.jp',
        '192.168.10.240 store.aimersoft.com',
        '192.168.10.240 store.iskysoft.com']

def hosts():
    output = open(r'C:\Windows\System32\drivers\etc\hosts', 'r',encoding= 'UTF-8')
    read = output.read()
    output.close()
    input = open(r'C:\Windows\System32\drivers\etc\hosts', 'a',encoding= 'UTF-8')
    for insid in hosts:
        if read.find(insid) == -1:
            input.write(insid)
            input.write("\n")
    input.close()

if __name__ == "__main__":
    hosts()
相關文章
相關標籤/搜索