ping¶
-
privex.helpers.net.
ping
(ip: str, timeout: int = 30) → bool[source]¶ Sends a ping to a given IPv4 / IPv6 address. Tested with IPv4+IPv6 using
iputils-ping
on Linux, as well as the default IPv4ping
utility on Mac OSX (Mojave, 10.14.6).Fully supported when using Linux with the
iputils-ping
package. Only IPv4 support on Mac OSX.Example Usage:
>>> from privex.helpers import ping >>> if ping('127.0.0.1', 5) and ping('::1', 10): ... print('Both 127.0.0.1 and ::1 are up') ... else: ... print('127.0.0.1 or ::1 failed to respond to a ping within the given timeout.')
Known Incompatibilities:
NOT compatible with IPv6 addresses on OSX due to the lack of a timeout argument with
ping6
NOT compatible with IPv6 addresses when using
inetutils-ping
on Linux due to separateping6
command
- Parameters
- Raises
ValueError – When the given IP address
ip
is invalid ortimeout
< 1- Return bool
True
if ping got a response from the given IP,False
if not