rust ping
Ping function implemented in rust.
Usage
To perform a basic ping, you can use the ping::new function to create a Ping instance and then call the send method. By default, on non-Windows systems, it attempts to use a DGRAM socket, falling back to RAW on Windows.
You can also configure various options like timeout, TTL, and socket type using the builder pattern:
use Duration;
To perform a ping using a domain name instead of an IP address, you can use any 3rd-party DNS resolver or ToSocketAddrs from the standard library:
Socket Types: DGRAM vs. RAW
Sending an ICMP package typically requires creating a raw socket, which often demands special privileges (e.g., running with sudo on Linux). This can introduce security risks.
Modern operating systems support unprivileged ping using dgram sockets, which do not require elevated privileges.
You can specify the socket type using the socket_type method of the Ping builder.
For Linux users, even if the kernel supports dgram ping, some distributions (like Arch) might disable it by default. More details: https://wiki.archlinux.org/title/sysctl#Allow_unprivileged_users_to_create_IPPROTO_ICMP_sockets
License
This library contains codes from https://github.com/knsd/tokio-ping, which is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
And other codes is licensed under
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)