栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661521.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号