如何在python里面直接修改hosts文件
def hostInit():
outsides = ''
output = open(r'C:\WINDOWS\system32\drivers\etc\HOSTS', 'w')
output.write(outsides)
output.close()
这里是清空hosts,如果你想设置hosts,可给outside赋值,比如:
def hostInit():
outsides = ['172.16.12.223 www.baidu.com',
'172.16.10.223 pan.baidu.com',
'172.16.12.111 un.baidu.com',
'172.16.12.223 passport.baidu.com']
output = open(r'C:\WINDOWS\system32\drivers\etc\HOSTS', 'w')
for i in outsides:
output.write(i)
output.write("\n")
output.close()