Ping的Python控制台和文本输出,包括 nr [重复]

Ping的Python控制台和文本输出,包括 nr [重复],第1张

Ping的Python控制台和文本输出,包括 n r [重复]
import subprocesshosts_file = open("hosts.txt","r")lines = hosts_file.readlines()hosts_file.close()for line in lines:    ping = subprocess.Popen(["ping", "-n", "3",line.strip()], stdout=subprocess.PIPE, stderr=subprocess.POPEN)    with open('PingResults.txt', 'ab') as fh:        for line in ping.stdout.readlines(): fh.write(line)    ping.stdout.close()

给我:

[torxed@faparch ~]$ python test.py && cat PingResults.txt PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.016 ms64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.023 ms64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.035 ms--- 127.0.0.1 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 1999msrtt min/avg/max/mdev = 0.016/0.024/0.035/0.009 msPING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.--- 192.168.0.1 ping statistics ---3 packets transmitted, 0 received, 100% packet loss, time 2008ms


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5667637.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存