问题遇到的现象和发生背景
记录DNS服务器是否丢包问题
问题相关代码,请勿粘贴截图
import os
import time
def dns():
i = 2698
success = 2698
fail = 0
while True:
dns_list = ["www.baidu.com", "www.sina.com.cn", "xa.58.com", "www.douyin.com",
"ai.taobao.com", "www.apple.com.cn", "www.jd.com", "cn.bing.com"]
os.system("ipconfig/flushdns")
for dns in dns_list:
ns = os.popen("nslookup "+dns+" 114.114.114.114")
time.sleep(2)
x = ns.read()
a = x.splitlines(keepends=True)
#print(x)
#print(a[-1::-1])
pathfile = "D:\python_code\pythondaima\socket\dns.txt"
file = open(pathfile, "a")
file.write(x)
i = i+1
if "Aliases: "+dns+"\n" in a[-1::-1]:
file.write("这服务器为114第%s次,解析成功\n" % i)
success = success+1
else:
file.write("这服务器为114第%s次,解析失败\n" % i)
fail = fail+1
file.write("*****服务器为114****一共执行%s,成功的次数%s,失败的次数%s,当前域名%s*********\n" %(i, success, fail, dns))
file.close()
dns()
这个是一个code片段另外一个是一模一样,就是文件存放的路径不一样,为什么第一个能占这么高内存呀??