### Install Gufo Ping with Pip Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/installation.md Use this command to install the Gufo Ping library. Ensure pip is available in your environment. ```bash $ pip install gufo_ping ``` -------------------------------- ### Complete Series Ping Example Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md This complete Python script demonstrates sending a series of ICMP echo requests to a specified address and printing the round-trip time for each successful reply or None for timeouts. It requires root privileges to run. ```python import asyncio import sys from gufo.ping import Ping async def main(addr: str): ping = Ping() async for rtt in ping.iter_rtt(addr): print(rtt) if __name__ == "__main__": asyncio.run(main(sys.argv[1])) ``` -------------------------------- ### Create Ping object Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Instantiate the Ping object. The constructor offers various configuration options for fine-tuning ping behavior. Defaults are sufficient for this example. ```python ping = Ping() ``` -------------------------------- ### Rebuild Rust Modules Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Install the package in editable mode to rebuild Rust modules for debugging and testing purposes. ```bash python -m pip install --editable . ``` -------------------------------- ### Ping a Host with Gufo Ping Source: https://github.com/gufolabs/gufo_ping/blob/master/README.md Instantiate the Ping class and use the ping method to get the Round Trip Time (RTT) for a given IP address. This is suitable for single ping checks. ```python ping = Ping() rtt = await ping.ping("127.0.0.1") ``` -------------------------------- ### Uninstall Gufo Ping with Pip Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/installation.md Use this command to remove Gufo Ping from your system. This is helpful for clean installations or freeing up space. ```bash $ pip uninstall gufo_ping ``` -------------------------------- ### Serve Documentation Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Rebuild and serve the project's documentation locally for review. This command is useful for checking documentation changes. ```bash $ mkdocs serve ``` -------------------------------- ### Build Package Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Run this command to build the package in both source distribution and wheel formats. Compiled packages will be placed in the 'dist/' directory. ```bash $ python -m build --sdist --wheel ``` -------------------------------- ### Check Python Code Lints Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Scan the project's Python code in 'examples/', 'src/', and 'tests/' for linting errors using ruff. ```bash $ ruff check examples/ src/ tests/ ``` -------------------------------- ### Generate HTML Coverage Report Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Create a detailed, line-by-line HTML report of code coverage. Open 'dist/coverage/index.html' in a browser to view. ```bash $ coverage html ``` -------------------------------- ### Import asyncio Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/single.md Import the asyncio module to run asynchronous code. This is necessary for using asynchronous functions like ping. ```python --8<-- "examples/single.py" ``` -------------------------------- ### Run Asynchronous Main Function Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Uses `asyncio.run()` to execute the asynchronous `main` function, passing the first command-line argument as the target IP address for the ping. ```python asyncio.run(main(sys.argv[1])) ``` -------------------------------- ### Check Code Formatting Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Verify that the code adheres to the project's Python code formatting standards using ruff. This command checks files in 'examples/', 'src/', and 'tests/'. ```bash $ ruff format --check examples/ src/ tests/ ``` -------------------------------- ### Run Test Suite Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Execute the project's test suite using pytest. Ensure Rust modules are rebuilt if they have changed. ```bash $ pytest -vv ``` -------------------------------- ### Import asyncio Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Import the asyncio module to run asynchronous code. This is necessary for using asynchronous functions. ```python import asyncio ``` -------------------------------- ### Run Tests for Coverage Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Execute the test suite with coverage tracking enabled using 'coverage run'. ```bash $ coverage run -m pytest -vv ``` -------------------------------- ### Fix Code Formatting Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Automatically fix Python code formatting errors in 'examples/', 'src/', and 'tests/' using ruff. ```bash $ ruff format examples/ src/ tests/ ``` -------------------------------- ### Import Ping from gufo.ping Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Import the Ping object from the gufo.ping library. This object provides the necessary API for sending pings. ```python from gufo.ping import Ping ``` -------------------------------- ### Define Asynchronous Main Function Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Defines an asynchronous function `main` that accepts an address to ping. Asynchronous functions are required for using `await` with Gufo Ping's methods. ```python async def main(addr: str): ``` -------------------------------- ### Import Gufo Ping and SelectionPolicy Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Imports the Ping object from `gufo.ping` and the `SelectionPolicy` enum. `SelectionPolicy.DGRAM` is used to enable DGRAM socket mode for ping probes. ```python from gufo.ping import Ping from gufo.ping.socket import SelectionPolicy ``` -------------------------------- ### Generate Coverage Report Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Generate a summary report of the code coverage after running tests with the coverage tool. ```bash $ coverage report ``` -------------------------------- ### Upgrade Gufo Ping with Pip Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/installation.md Run this command to upgrade to the latest version of Gufo Ping. This is useful for accessing new features or bug fixes. ```bash $ pip install --upgrade gufo_ping ``` -------------------------------- ### Create Ping Object with DGRAM Policy Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Initializes a `Ping` object, configuring it to use DGRAM sockets by setting the `policy` parameter to `SelectionPolicy.DGRAM`. This ensures ICMP echo requests are sent via DGRAM sockets. ```python policy=SelectionPolicy.DGRAM ``` -------------------------------- ### Import asyncio for DGRAM Ping Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Imports the asyncio library, which is necessary for running asynchronous code, including the DGRAM ping functionality. ```python import asyncio ``` -------------------------------- ### Check for main module Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Ensure the script is run as the main module before executing the main asynchronous function. This is a standard Python practice. ```python if __name__ == "__main__": pass ``` -------------------------------- ### Iterate RTTs for a Host with Gufo Ping Source: https://github.com/gufolabs/gufo_ping/blob/master/README.md Use the iter_rtt method to send a series of probes to a host and asynchronously iterate over the Round Trip Times (RTTs). Specify the count for the number of probes. ```python ping = Ping() async for rtt in ping.iter_rtt("127.0.0.1", count=5): print(rtt) ``` -------------------------------- ### Print RTT results Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Print the result of each iteration, which will be the measured Round-Trip Time (RTT) in seconds or None if the request timed out. ```python print(rtt) ``` -------------------------------- ### Check for Main Module Execution Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Ensures that the script's main execution logic runs only when the script is executed directly, not when imported as a module. ```python if __name__ == "__main__": ``` -------------------------------- ### Import sys for CLI Arguments Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Imports the sys module to access command-line arguments. Note: For real-world applications, use `argparse` or similar libraries instead of `sys.argv`. ```python import sys ``` -------------------------------- ### Check Python Code Static Typing Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/dev/testing.md Perform static type checking on the 'src/' directory using mypy with strict mode enabled. ```bash $ mypy --strict src/ ``` -------------------------------- ### Iterate over ping results Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/series.md Use the asynchronous iterator `Ping.iter_rtt()` to send ICMP echo requests and receive round-trip times (RTT). It yields RTT as a float on success or None on failure for each attempt. The address is the only mandatory parameter. ```python async for rtt in ping.iter_rtt(addr): pass ``` -------------------------------- ### Perform Single Ping Probe with DGRAM Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Executes a single ping probe to the specified IP address using an asynchronous call to `Ping.ping`. The function returns the round-trip time (RTT) in seconds on success or `None` on failure. ```python rtt = await ping.ping(addr) ``` -------------------------------- ### Print Ping Result Source: https://github.com/gufolabs/gufo_ping/blob/master/docs/examples/dgram.md Prints the result of the ping operation. This will be the measured round-trip time (RTT) if the ping was successful, or `None` if it timed out or failed. ```python print(rtt) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.