fujiapple852 / trippy

A network diagnostic tool
https://trippy.cli.rs
Apache License 2.0
3.8k stars 82 forks source link

Better text mode #1373

Closed Albonycal closed 3 weeks ago

Albonycal commented 3 weeks ago

trippy already has a few useful output modes, but I think a normal text based (traceroute like) output will also be handy for cases like copy pasting to an instant messaging platform or email.

I prefer sending it as text instead of screenshot because it's easier to copy IP addresses and things like that.

daryll-swer commented 3 weeks ago

Agreed, a 'text-mode' that's 1:1 copy/paste ready for professional emails and the like would be great for NOC.

c-git commented 3 weeks ago

Would this be a text version of what would be on the screen (if yes at what point) or some summary type output?

c-git commented 3 weeks ago

If it's the first one there is a flag to preserve the output on exit --tui-preserve-screen would that meet your needs?

Albonycal commented 3 weeks ago

Would this be a text version of what would be on the screen (if yes at what point) or some summary type output?

A summary yes, looks the -m pretty option does the trick for email, whatsapp. But some platforms mess up the formatting (like Signal, telegram)

Unfortunately the same problem exists even if you enable the preserve-tui option

fujiapple852 commented 3 weeks ago

@Albonycal is the output of -m markdown simple enough for Signal et. al.?

$ sudo trip 1.1.1.1 -C 2 -m markdown
| Hop | IPs            | Addrs                          | Loss% | Snt | Recv | Last | Avg  | Best | Wrst | StdDev |
|-----|----------------|--------------------------------|-------|-----|------|------|------|------|------|--------|
| 1   | 192.168.1.1    | 192.168.1.1                    | 0.0   | 2   | 2    | 12.6 | 11.7 | 10.7 | 12.6 | 0.9    |
| 2   | 219.79.120.2   | xxx.netvigator.com             | 0.0   | 2   | 2    | 10.0 | 9.8  | 9.6  | 10.0 | 0.2    |
| 3   | 10.193.233.2   | 10.193.233.245                 | 0.0   | 2   | 2    | 8.6  | 8.6  | 8.5  | 8.6  | 0.0    |
| 4   | 10.195.45.190  | 10.195.42.190                  | 0.0   | 2   | 2    | 7.6  | 8.0  | 7.6  | 8.4  | 0.4    |
| 5   | 123.255.90.246 | cloudflare1-lacp-100g.hkix.net | 50.0  | 2   | 1    | 16.0 | 16.0 | 16.0 | 16.0 | 0.0    |
| 6   | 103.22.203.75  | 103.22.203.75                  | 0.0   | 2   | 2    | 9.3  | 9.5  | 9.3  | 9.7  | 0.2    |
| 7   | 1.1.1.1        | one.one.one.one                | 0.0   | 2   | 2    | 11.2 | 10.9 | 10.6 | 11.2 | 0.3    |
fujiapple852 commented 3 weeks ago

I think you are asking for something like this:

traceroute to 1.1.1.1 (1.1.1.1), 64 hops max, 52 byte packets
 1  linksys01983 (192.168.1.1) 5.490 ms  5.305 ms  6.031 ms
 2  xxx.netvigator.com (219.79.120.253) 7.107 ms  7.382 ms  7.685 ms
 3  10.193.223.2 (10.193.233.245) 5.191 ms  4.863 ms  7.155 ms
 4  10.195.12.180 (10.195.42.190) 7.167 ms  5.227 ms  4.817 ms
 5  cloudflare1-lacp-100g.hkix.net (123.255.90.246) 8.318 ms  15.861 ms  0.000 ms
 6  103.22.203.79 (103.22.203.79) 9.304 ms  8.224 ms  7.152 ms
    103.22.203.75 (103.22.203.75) 9.304 ms  8.224 ms  7.152 ms
 7  one.one.one.one (1.1.1.1) 7.066 ms  6.721 ms  6.886 ms

In which case, maybe just use traceroute instead of Trippy?

fujiapple852 commented 3 weeks ago

Another option is to use the json mode and feed the output through a template tool like jinja2:

sudo trip 1.1.1.1 -m json | jinja2 trippy.j2

Where the template is something like (from ChatGPT):

traceroute to {{ info.target.hostname }} ({{ info.target.ip }})
{% for hop in hops %}
{{ hop.ttl }}{% if hop.hosts %}{% for host in hop.hosts %} {{ host.hostname }} ({{ host.ip }}) {{ hop.last }} ms  {{ hop.best }} ms  {{ hop.worst }} ms {% endfor %}{% else %} *** {% endif %} {% endfor %}

I just tried with minijinja-cli using the above template:

$ sudo trip 1.1.1.1 -C 1 -m json | minijinja-cli -f json trippy.j2 -

The output is a bit wonky (i'm not a jinja2 expert), but i'm sure with some fiddling it could be made to look as you want.

traceroute to example.com (93.184.215.14)

1 100.101.91.146 (100.101.91.146) 258.45 ms  258.45 ms  260.02 ms
2 ***
3 10.80.171.21 (10.80.171.21) 259.06 ms  259.06 ms  261.18 ms
4 138.197.259.124 (138.197.259.124) 257.99 ms  257.99 ms  259.39 ms
5 143.244.12.142 (143.244.12.42) 259.53 ms  259.53 ms  261.87 ms
6 143.244.224.150 (143.244.224.150) 258.20 ms  258.20 ms  259.17 ms
7 143.244.224.149 (143.244.224.149) 258.98 ms  258.33 ms  258.98 ms
8 slou-b2-link.ip.twelve99.net (213.248.88.246) 258.19 ms  258.19 ms  259.02 ms
9 ***
10 ***
11 nyk-b17-link.ip.twelve99.net (62.115.137.15) 334.98 ms  334.98 ms  334.98 ms
12 edgio-ic-317660.ip.twelve99-cust.net (62.115.147.201) 333.48 ms  333.48 ms  341.77 ms
13 ae-66.core1.nyd.edgecastcdn.net (152.195.69.133) 328.22 ms  328.22 ms  355.28 ms
14 93.184.215.14 (93.184.215.14) 331.83 ms  331.83 ms  344.48 ms
Albonycal commented 3 weeks ago

Closing this issue, this is a bug on the platform side anyway, they should be parsing these messages better. And traceroute works for this :+1: