txt文件按日期时间自动生成,并将真假结果分别输入对应txt文件中.在网上找了很多例子最终还是没写成功.希望大神可以帮我完善一下代码.感谢🙏#coding='utf-8'importos,sysfromra...
txt文件按日期时间自动生成,并将真假结果分别输入对应txt文件中.在网上找了很多例子最终还是没写成功.希望大神可以帮我完善一下代码.感谢🙏#coding='utf-8'import os,sysfrom random import sampletruelist = []falselist = []IP = ['192.168.1.1','192.168.0.1','192.168.1.2']for i in sample(IP,2): ping = os.system('ping -c 3 %s'%i) if ping: falselist.append(i) else: truelist.append(i)print('truelist:' + str(truelist))print('falselist:' + str(falselist))
#coding='utf-8'
import os,sys
from random import sample
import time
import datetime
truelist = []
falselist = []
IP = ['192.168.1.1','192.168.0.1','192.168.1.2']
f = open(datetime.datetime.now().strftime("%Y%m%d%H%M%S") + ".txt", "w")
for i in sample(IP,2):
ping = os.system('ping -c 3 %s'%i)
if ping:
falselist.append(i)
else:
truelist.append(i)
print('truelist:' + str(truelist), file = f)
print('falselist:' + str(falselist), file = f)
f.close()