python添加域名host
时间:2023-02-02 01:52:01 | 来源:建站知识
时间:2023-02-02 01:52:01 来源:建站知识
# -*- coding: utf-8 -*-
import sys
# window下hosts路径HOSTS_PATH = r'C:/WINDOWS/system32/drivers/etc/HOSTS'
# mac/linux系统hosts路径为/private/etc/hosts# HOSTS_PATH = r'/private/etc/hosts'
def set_env_hosts(): hosts_detail = D:/xxx/resources/test_hosts (把域名配置放在txt文件加下的)
content = open(hosts_detail, 'r')
lines = content.readlines()
content.close()
output = open(HOSTS_PATH, 'w')
for line in lines:
output.write(line)
http://logger.info("环境hosts已配置")
output.close()
def clear_hosts(): with open(HOSTS_PATH, 'w') as hosts_files:
hosts_files.truncate(0)
if __name__ == "__main__":
set_env_hosts()
# clear_hosts()