由于学校教育网时常出现问题导致ipv6不能访问,对于我这种靠v6访问Google的人来说,需要来回切换hosts文件。下面脚本用来执行hosts的替换。
p.s:学python之后的第一个小程序
import os.path
import shutil
def copyIpv6Hosts(sourceDir,targetDir):
for files in os.listdir(sourceDir):
sourcefile = os.path.join(sourceDir,files)
targetfile = os.path.join(targetDir,files)
if os.path.isfile(targetfile) and files=="hosts":
os.remove(targetfile)
if os.path.isfile(sourcefile) and file