[問題] ping ip 取得延遲時間

看板Python作者 (【積π】)時間5年前 (2019/11/25 09:21), 編輯推噓0(002)
留言2則, 1人參與, 5年前最新討論串1/1
想請問板上各位先進 有辦法藉由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

11/25 11:16, 5年前 , 1F
你可以用 subprocess 去取得輸出 之後再用 re 取得
11/25 11:16, 1F

11/25 11:16, 5年前 , 2F
要的部份
11/25 11:16, 2F
文章代碼(AID): #1TsooiGl (Python)
文章代碼(AID): #1TsooiGl (Python)