作者ctr1 (【積π】)
看板Python
標題[問題] ping ip 取得延遲時間
時間Mon Nov 25 09:21:46 2019
想請問板上各位先進
有辦法藉由python取得延遲時間如下紅字部分
目前只會做到ping host取得狀態
import os
hostname = "google.com" #example
response = os.system("ping -c 1 " + hostname)
if response == 0:
print(hostname, 'is up!')
else:
print(hostname, 'is down!')
想要把延遲時間紀錄於純文字中
謝謝了
Ping 8.8.8.8 (使用 32 位元組的資料):
回覆自 8.8.8.8: 位元組=32 時間=
12ms TTL=52
回覆自 8.8.8.8: 位元組=32 時間=
3ms TTL=52
回覆自 8.8.8.8: 位元組=32 時間=
2ms TTL=52
回覆自 8.8.8.8: 位元組=32 時間=
2ms TTL=52
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.242.44.65 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1574644908.A.42F.html
→ dododavid006: 你可以用 subprocess 去取得輸出 之後再用 re 取得 11/25 11:16
→ dododavid006: 要的部份 11/25 11:16