iT邦幫忙

0

python寫偵測ping網路程式

  • 分享至 

  • xImage

python寫偵測ping網路程式, 每隔一段時間跑一次, 若有異常就自動發通知

請問要怎麼寫,求大神

obarisk iT邦研究生 1 級 ‧ 2022-11-11 07:59:09 檢舉
keyword: icmp

https://network.fasionchan.com/zh_CN/latest/practices/ping-by-icmp-py.html
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
tryit
iT邦研究生 4 級 ‧ 2022-11-10 23:59:41
import time
def check_ping():
    hostname = "XXX.com"
    response = os.system("ping -c 1 " + hostname)
    # and then check the response...
    if response == 0:
        pingstatus = "Network Active"
    else:
        pingstatus = "Network Error"
    
    return pingstatus
while 1:
    print(check_ping())
    time.sleep(3600)

擷取自:https://stackoverflow.com/questions/26468640/python-function-to-test-ping
google關鍵字: python ping test

zoobllzz iT邦新手 5 級 ‧ 2023-07-08 00:33:56 檢舉
import time
import os
def check_ping():
    hostname = "XXX.com"
    response = os.system("ping -c 1 " + hostname)
    # and then check the response...
    if response == 0:
        pingstatus = "Network Active"
    else:
        pingstatus = "Network Error"
    
    return pingstatus
while 1:
    print(check_ping())
    time.sleep(3600)

我要發表回答

立即登入回答