帮我看看count_true计数不正常
本帖最后由 jitianmoshen 于 2020-11-22 09:57 编辑谁帮我看看怎么改,谢谢
def ping_IP(IP_QUEUE):
count_true = 0
while not IP_QUEUE.empty():
ip = IP_QUEUE.get().strip('\n')
# print (ip)
res = subprocess.call(f"ping -w 1000 -n 1 {ip}", stdout=subprocess.PIPE, shell=True)
# print (res)
today = datetime.datetime.now().strftime("%Y年%m月%d日%H:%M:%S")
if res == 0:
count_true += 1
h = subprocess.getoutput(f"Ping {ip}")
# print (h)
if 'TTL=' in h:
if "Average" in h:
res = f"网络可以正常连通,平均延时 = {h.split('Average = ')}"
logging.info(f"{today} IP ={ip} {res}")
elif "平均" in h:
res = f"网络可以正常连通,平均延时 = {h.split('平均 = ')}"
logging.info(f"{today} IP ={ip} {res}")
else:
res = f"网络可以正常连通."
logging.info(f"{today} IP ={ip} {res}")
#else:
#res = '网络连接失败!\n'
#print(res)
print(count_true)
logging.info(f"一共ping通 {count_true} 个ip.") 本帖最后由 jitianmoshen 于 2020-10-10 16:21 编辑
像这样
应该是多线程弄的{:10_269:} 我改下计数方式吧{:10_254:}
页:
[1]