【发布时间】:2021-10-11 22:34:26
【问题描述】:
嘿,我制作了一个小工具,可以在 python 中 ping 任何网站/ip。
所以我的机器人可以找到但我不想添加一个功能来获取平均值。
我的代码如下:
import os, time, requests
url = 'WEBHOOK URL'
while True:
hostname = "google.com"
response = os.system("ping -c 1 " + hostname)
if response == 0:
print (hostname, 'is online!')
data = {
"content" : "Message content",
"username" : "Author name"
}
data["embeds"] = [
{
"description" : "Google is onligne",
"title" : "TITLE EMBEDS"
}
]
requests.post(url, json = data)
time.sleep(900)
else:
data = {
"content" : "Message content",
"username" : "Author name"
}
data["embeds"] = [
{
"description" : "Google is offligne",
"title" : "TITTLE EMBEDS"
}
]
requests.post(url, json = data)
print (hostname, 'is down!')
time.sleep(900)
这段代码工作得很好,但我想通过获得平均速度来完成我的代码:
像这样:
平均速度是 ping 的结果。
当我这样做时:
print (response)
我明白了:
0
我不想得到类似的东西:
Average = 49ms
但我不知道该怎么做......
感谢您的帮助
PYTHONPING 解决的问题
【问题讨论】:
-
已经有一个关于这个主题的完整问题,您可以在其中找到您需要的所有信息here
-
这能回答你的问题吗? Measuring ping latency of a server - Python
-
不,我需要从 ping 命令中提取平均速度