【发布时间】:2018-05-24 11:08:38
【问题描述】:
import os
host = "www.yahoo.com"
test = os.system("ping -c 10 " + host + " | tail -1| awk '{print $4}' | cut -d '/' -f 2")
print(test)
def check_ping():
hostname = "www.google.com"
response = os.system("ping -c 10 " + hostname + " | tail -1| awk '{print $4}' | cut -d '/' -f 2")
print(int(response))
if response > 0:
print("boo")
print("Network Active. Average response time is: " + str(response))
else:
print("Network Error: No connection to destination")
check_ping()
将其设置为浮点数
[root@web python3]# python3 testNet.py
8.113
0.0
网络错误:没有连接到目的地
添加了另一个 url 并将其设置为 int
[root@web python3]# python3 testNet.py
44.992
0
11.377
0
网络错误:没有连接到目的地
为什么当你尝试用它做任何事情时,当你 ping 它时它设置为零? 其他的印刷品只是看看它是如何通过的
【问题讨论】:
-
您是否费心阅读文档? docs.python.org/3/library/os.html#os.system
-
我投票决定将此问题作为离题结束,因为答案在文档中以所有字母拼写。
-
显然我错过了那部分。
标签: python linux python-3.x