Asynchronous code must be executed in the asynchronous functions, or coroutines.
So we define our function as async. We expect an address to ping as the
addr argument.
First we need to create Ping object. Ping constructor offers a lots
of configuration variables for fine-tuning. Refer to the
Ping reference
for further details. Defaults are good enough for our tutorial, so
we ommited them.
Run single ping probe. Ping.ping is asynchronous function, so note
the await keyword. The only mandatory parameter is IP address.
Gufo Ping detects IPv4/IPv6 usage, so all we need is to pass an address.
Function may accept the additional parameters for fine-tuning,
Refer to the
Ping.ping reference
for details.
Ping returns:
In case of success: Round-trip-time (RTT), as float, measured in seconds.
Lets check the faulty cause. RFC-5737 defines the special range
of addresses - 192.0.2.0/24, which can be used as unresponsible addresses.
So, lets ping a 192.0.2.1:
$ sudo python3 examples/single.py 192.0.2.1
None
After second or so of awaiting we finally got a None, which means our
request is timed out.