A pure python ping library.
The ping library is inspired by MultiPing and as a practice to raw socket and ICMP/IP of my own.
- Pure python implementation, no 3rd party library is required.
- class
Monitorfor periodically monitoring multiple hosts.
pip install .
import ping
host = "www.google.com"
timeout = 0.5
interval = 1.0
p = ping.Ping()
success, dt = p.ping_once(host, timeout=timeout)
suc_dt_list = p.ping_seq(host, timeout=timeout, interval=interval)
host_dt_map = p.ping_multi([host,], timeout=timeout)
:::warning
tracert function is currently only work on linux.
You may need to configure firewall to enable this feature.
:::
import ping
host = "www.google.com"
timeout = 0.5
max_hops = 30
route_list = ping.tracert(host, timeout, max_hops)
import ping
hosts = [
"www.google.com",
"www.youtube.com",
]
timeout = 0.5
interval = 1.0
m = ping.Monitor(interval, timeout)
for host in hosts:
m.subscribe(host)
m.resume()
# ...
pmr = m.get()
- python >= 3.6
ping library is distributed under MIT license.