udp_pinger 0.1.0

A library for pinging devices using unprivileged UDP packets.
Documentation

UDP Pinger

An implementation of a UDP-based ping utility. This library does not require root privileges, unlike ICMP-based ping utilities.

Usage

Rust Example

use std::{net::Ipv4Addr, time::Duration};

use udp_pinger;

fn main() {
    let mut p = udp_pinger::Pinger::try_new(Ipv4Addr::new(192, 168, 1, 34)).unwrap();
    p.ping_once(Duration::from_secs(1)).unwrap();
    p.start(Duration::from_secs(1), Duration::from_millis(500)).unwrap();
    loop {
        let opt_sample = p.wait_for_sample(Duration::from_secs(10));
        if let Ok(sample) = opt_sample {
            println!("Sample: {}", sample);
        } else {
            println!("No sample received in 10 seconds, exiting.");
            break;
        }
    }
}

Python Bindings

from udp_pinger import Pinger

def main():
    p = Pinger("192.168.1.34")
    p.ping_once(1.0)
    p.start(1, 0.5)
    while True:
        sample = p.wait_for_sample(10)
        if sample is not None:
            print(f"Sample: {sample}")
        else:
            print("No sample received in 10 seconds, exiting.")
            break

Features

  • py: Enables Python bindings using PyO3.
  • alternate_port: Uses an alternate UDP port (33434) for sending packets instead of the default (59999).

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.