Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 136ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
s

system-health

Recently created Least recently created Recently updated Least recently updated

timmy / Ping 網路連線檢查工具

Last active 5 hours ago internet-check network-diagnostics network-monitoring networking ping python system-health

這段程式碼透過多次執行系統的 ping 指令來測試指定主機(預設為 8.8.8.8)的連線狀態,並根據多次成功的回應判斷網路是否穩定連通。

0 0 0 1
1 import subprocess
2 import platform
3 import time
4
5 def ping_once(host):
6 """
7 使用系統的 ping 指令對指定 host 發送一次封包,
8 回傳 True 代表 ping 成功,False 代表失敗。
9 """
10 # 根據作業系統決定參數:Windows 用 -n,其他平台用 -c