(Mar-03-2022, 05:30 AM)Skaperen Wrote: i searched PyPi but nothing looked promising. it's hard to search there
A standard search eg google you should be able to find something.
These took me not long time to find,can also test all.
icmplib |
pythonping |
ping3.
icmplib(GitHub) maybe the best one a modern implementation of the ICMP protocol in Python.
from icmplib import ping, multiping, traceroute, resolve
print(ping('google.com', count=4))
Output:
142.250.74.142
------------------------------------------------------------
Packets sent: 4
Packets received: 4
Packet loss: 0.0%
Round-trip times: 44.0 ms / 46.749 ms / 51.999 ms
Jitter: 2.666 ms
------------------------------------------------------------
The rest.
import subprocess
from pythonping import ping
from ping3 import verbose_ping
# The one on OS
output = subprocess.run(['ping', 'google.com'], capture_output=True, encoding='utf-8')
print(output.stdout)
print('-' * 50)
# pip install pythonping
ping('google.com', verbose=True)
print('-' * 50)
# pip install ping3
verbose_ping('google.com')
Output:
Pinging google.com [142.250.74.142] with 32 bytes of data:
Reply from 142.250.74.142: bytes=32 time=39ms TTL=50
Reply from 142.250.74.142: bytes=32 time=45ms TTL=50
Reply from 142.250.74.142: bytes=32 time=50ms TTL=50
Reply from 142.250.74.142: bytes=32 time=46ms TTL=50
Ping statistics for 142.250.74.142:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 39ms, Maximum = 50ms, Average = 45ms
--------------------------------------------------
Reply from 142.250.74.142, 29 bytes in 44.09ms
Reply from 142.250.74.142, 29 bytes in 39.87ms
Reply from 142.250.74.142, 29 bytes in 39.8ms
Reply from 142.250.74.142, 29 bytes in 39.8ms
--------------------------------------------------
ping 'google.com' ... 39ms
ping 'google.com' ... 39ms
ping 'google.com' ... 39ms
ping 'google.com' ... 39ms