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-pingon Linux, as well as the default IPv4pingutility on Mac OSX (Mojave, 10.14.6).Fully supported when using Linux with the
iputils-pingpackage. 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
ping6NOT compatible with IPv6 addresses when using
inetutils-pingon Linux due to separateping6command
- Parameters
- Raises
ValueError – When the given IP address
ipis invalid ortimeout< 1- Return bool
Trueif ping got a response from the given IP,Falseif not