rusty-ping

ยท SourceTube: Version control for the omg.lol community

4 min read Original article โ†—

A replacement for prettyping.
A very simple ping utility that tries to be as visual as possible.

Tested on Linux only.
โš ๏ธ: Rusty-ping currently only supports unprivilegied ICMP, check ยซ known bugs ยป section.

Install

From crates.io :

$ cargo install rusty-ping

From source :

$ git clone https://source.tube/ache/rusty-ping
$ cd rusty-ping
$ cargo install --path .

You can also clone :

Usage

$ rusty-ping <host>

Or before installation :

$ cargo run -- <host>

Uninstall

$ cargo uninstall rusty-ping

โš ๏ธ Don't forget to remove any shell integration !

Shell integration

Rusty-ping doesn't use a config file to keep things as simple as possible.
The goal, for me, is to type pp to quickly do a ping.

I will not call this project pp as it may conflict with other CLI tools. So you should set up a shell alias (e.g., pp, rp, or any name you prefer) via shell integration.

I primarily use Fish, so if anything breaks with bash or zsh, please send me an email.

Fish

I prefer to use fish abbreviations.

In $HOME/.config/fish/function/pp.fish or $HOME/.config/fish/conf.d/pp.fish :

abbr --add pp rusty-ping --stats --status --default-target 2606:4700:4700::1111

But a function works too.

function pp
    rusty-ping --stats --status --default-target 2606:4700:4700::1111
end

Bash / zsh

You can just use a function :

function pp {
    rusty-ping --stats --legend --status --default-target 2606:4700:4700::1111
}

"User Interface"

Here is the full UI and the explanations :

rusty-ping --stats --status --default-target git.ache.one --legend
0 โ– 30 โ–„ 50 โ–† 70 โ–ˆ 90 โ–‚ 120 โ–… 150 โ–ˆ 170 โ–‚ 190 โ–„ 210 โ–† 240 ? <-- The legend (--legend)
PING git.ache.one (145.239.86.0)                            <-- The status line (--status)
โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„?                                                   <-- The ping line
0/9 (0.0%) | โŒŠ34โŒ‹ โŒˆ35โŒ‰ [35] [ฮ”0]ms                          <-- Statistics on every packet (--stats)
0/9 (0.0%) | โŒŠ34โŒ‹ โŒˆ35โŒ‰ [35] [ฮ”0]ms                          <-- Statistics on the last 30 packets (--stats)

The legend indicates which characters correspond to which RTT in the ping line.
On the ping line, each character represents an ICMP packet sent.

? => Packet not yet received ! => Packet lost

The statistics

RTT is expressed in miliseconds.

 โ”โ”> Number of packets lost / Total sent (Percentage of packets lost)
 โ”‚         โ”โ”> Just a separator
0/9 (0.0%) | โŒŠ36โŒ‹ โŒˆ56โŒ‰ [40] [ฮ”4]ms
              โ”‚    โ”‚    โ”‚    โ”•โ”> The mean absolute difference
              โ”‚    โ”‚    โ”‚        to the average RTT
              โ”‚    โ”‚    โ”•โ”> The average RTT
              โ”‚    โ”•โ”> The maximum RTT
              โ”•โ”> The minimum RTT

Technical Notes

Rusty-ping does NOT use the ping command.
It isn't tied to Bash or any specific shell.

๐Ÿ› Known "bugs" ๐Ÿชฒ ๐Ÿž

The list of ยซ bugs ยป that may be fixed.

ICMP unprivilegied must be allowed

rusty-ping doesn't implement privilegied ping. You must have unprivilegied ping allowed (default on Arch Linux, not the default in the Linux kernel).

Check with sysctl :

$ sysctl net.ipv4.ping_group_range
net.ipv4.ping_group_range = 1 0

Change it to 0 to 2147483647 to allow every user to create ICMP_PROTO datagram sockets.

# sysctl net.ipv4.ping_group_range="0 2147483647"  # Reset on reboot
# echo "net.ipv4.ping_group_range = 0 2147483647" | tee /etc/sysctl.d/99-ping.conf  # Make it permanent

Repetitive UI

If there is not enougth lines to print the whole UI, the terminal will scroll and shift the ping line.
It will so happen at each ping and the whole UI will be shifted more and more.

Some code should detect that there is not enougth lines to print everything and fail.

Rust dependencies:

  • clap to parse args.
  • ping crate to actually do the ping.
  • term_size to print the legend on a single line.
  • tokio for mpsc, the default mpsc queue seems to be deprecated;

License

CeCILL 2.1