fujiapple852 / trippy

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

Question Mark Symbol #947

Closed Jev1337 closed 8 months ago

Jev1337 commented 8 months ago

Describe the bug A question mark symbol on the graphs.

To Reproduce Just running the program.

Expected behavior No weird symbols

Screenshots image

Environment Info

Additional context I hope this wasn't an already asked issue!

Jev1337 commented 8 months ago

I would like to also ask how are settings changed in order to enable ASN info and Geolocation, which button to use?

c-git commented 8 months ago

Yes unfortunately this is an artifact of the terminal. IIRC it was powershell that does this. But if you use the normal cmd then it works fine. Please test in the other one and let me know if it still happens for you.

c-git commented 8 months ago

I would like to also ask how are settings changed in order to enable ASN info and Geolocation, which button to use?

For this part I will have to test and get back to you as I don't normally use that feature. Or if if one of the others remember off hand and get to it before me they should be able to point you in the right direction.

c-git commented 8 months ago

I checked the readme in the usage examples section and I see it has an example of how to do geoip and while the program is running if you go to settings by pressing 's' I'd think you should see the file there. Let me know if this helps.

Jev1337 commented 8 months ago

I checked the readme in the usage examples section and I see it has an example of how to do geoip and while the program is running if you go to settings by pressing 's' I'd think you should see the file there. Let me know if this helps.

Pressing 's' would show up the settings however I don't know how to change them

Yes unfortunately this is an artifact of the terminal. IIRC it was powershell that does this. But if you use the normal cmd then it works fine. Please test in the other one and let me know if it still happens for you.

I'm using the normal cmd as admin, I tried PS 7 in case you meant the oposite but it's the same issue. image

Even status indicator seems to be off compared to the readme's images.

c-git commented 8 months ago

Pressing 's' would show up the settings however I don't know how to change them

One way to change the setting is to use the command line options to set it like it shows in the examples. If I recall correctly you can also use a settings file but try the command line option first as that's easier.

I'm using the normal cmd as admin, I tried PS 7 in case you meant the oposite but it's the same issue.

I know one of them was doing it. I don't remember which. I will try it hopefully later and let you know. I use Linux normally so I don't usually need to remember which one, but I will check for you.

fujiapple852 commented 8 months ago

@Jev1337 I'm not overly familiar with Windows, but from a brief search it does seem like there are known issues (and workarounds) for showing some unicode code pages and so this is not an issue specific to Trippy. The "best" solution seems to be to use Windows Console Preview whcih does not suffer from these issues.

Trippy (and in particular Ratatui, the TUI library) uses various unicode characters to display the charts and other things. Specifically, the Samples is a Ratatui Sparkline and uses the following unicode characters:

    pub const FULL: &str = "█";
    pub const SEVEN_EIGHTHS: &str = "▇";
    pub const THREE_QUARTERS: &str = "▆";
    pub const FIVE_EIGHTHS: &str = "▅";
    pub const HALF: &str = "▄";
    pub const THREE_EIGHTHS: &str = "▃";
    pub const ONE_QUARTER: &str = "▂";
    pub const ONE_EIGHTH: &str = "▁";
Jev1337 commented 8 months ago

@Jev1337 I'm not overly familiar with Windows, but from a brief search it does seem like there are known issues (and workarounds) for showing some unicode code pages and so this is not an issue specific to Trippy. The "best" solution seems to be to use Windows Console Preview whcih does not suffer from these issues.

Trippy (and in particular Ratatui, the TUI library) uses various unicode characters to display the charts and other things. Specifically, the Samples is a Ratatui Sparkline and uses the following unicode characters:

    pub const FULL: &str = "█";
    pub const SEVEN_EIGHTHS: &str = "▇";
    pub const THREE_QUARTERS: &str = "▆";
    pub const FIVE_EIGHTHS: &str = "▅";
    pub const HALF: &str = "▄";
    pub const THREE_EIGHTHS: &str = "▃";
    pub const ONE_QUARTER: &str = "▂";
    pub const ONE_EIGHTH: &str = "▁";

Thanks; I already tried changing fonts, reverting back to legacy cmd, and trying a windows 10 machine but nothing, I will try out the preview console later and report back!

fujiapple852 commented 8 months ago

@Jev1337 to add to what @c-git said and for the benefit of others who may ask a similar question in the future:

To enable AS lookup you use the --dns-lookup-as-info (-z) option. However, AS lookup is not supported for the default system DNS resolver and so you need to pick one of the others (i.e. Google's 8.8.8.8) with the --dns-resolve-method (-r) option. The command therefore becomes:

trip example.com -r google -z

To enable GeoIp information you need a MaxMind GeoIp mmdb database file, which you provide with the --geoip-mmdb-file (-G) option. Note that from Trippy 0.10.x, both MaxMind and IpInfo mmdb files may be used. You can optionally adjust how GeoIp information is displayed with the --tui-geoip-mode option. Therefore, your command could be:

trip example.com --geoip-mmdb-file GeoLite2-City.mmdb --tui-geoip-mode short

To avoid providing these options every time you run Trippy you can set them permanently in a trippy.toml config file.

Combining these, your config file would become:

[dns]
dns-resolve-method = "google"
dns-lookup-as-info = true

[tui]
geoip-mmdb-file = "/path/to/GeoLite2-City.mmdb"
tui-geoip-mode = "short"

Pressing 's' would show up the settings however I don't know how to change them

To confirm that the settings dialog is read-only for the moment, something we aim to improve in the future.

c-git commented 8 months ago

Hi @Jev1337 I tested and you're right both cmd and power shell show that. I tried windows terminal and that worked for me. I didn't install it so I'm guessing it came with Windows. I almost never boot up into windows so really not sure if I did it years ago.

image

I just typed terminal in the start menu then right clicked on the program in red and chose Run as Administrator and that worked.

image

Jev1337 commented 8 months ago

@Jev1337 to add to what @c-git said and for the benefit of others who may ask a similar question in the future:

To enable AS lookup you use the --dns-lookup-as-info (-z) option. However, AS lookup is not supported for the default system DNS resolver and so you need to pick one of the others (i.e. Google's 8.8.8.8) with the --dns-resolve-method (-r) option. The command therefore becomes:

trip example.com -r google -z

To enable GeoIp information you need a MaxMind GeoIp mmdb database file, which you provide with the --geoip-mmdb-file (-G) option. Note that from Trippy 0.10.x, both MaxMind and IpInfo mmdb files may be used. You can optionally adjust how GeoIp information is displayed with the --tui-geoip-mode option. Therefore, your command could be:

trip example.com --geoip-mmdb-file GeoLite2-City.mmdb --tui-geoip-mode short

To avoid providing these options every time you run Trippy you can set them permanently in a trippy.toml config file.

Combining these, your config file would become:

[dns]
dns-resolve-method = "google"
dns-lookup-as-info = true

[tui]
geoip-mmdb-file = "/path/to/GeoLite2-City.mmdb"
tui-geoip-mode = "short"

Pressing 's' would show up the settings however I don't know how to change them

To confirm that the settings dialog is read-only for the moment, something we aim to improve in the future.

Hi @Jev1337 I tested and you're right both cmd and power shell show that. I tried windows terminal and that worked for me. I didn't install it so I'm guessing it came with Windows. I almost never boot up into windows so really not sure if I did it years ago.

image

I just typed terminal in the start menu then right clicked on the program in red and chose Run as Administrator and that worked.

image

Thank you both, trying out the "Terminal" instead of the normal CMD works, and the ASN functionality works as well!

Jev1337 commented 8 months ago

@Jev1337 to add to what @c-git said and for the benefit of others who may ask a similar question in the future:

To enable AS lookup you use the --dns-lookup-as-info (-z) option. However, AS lookup is not supported for the default system DNS resolver and so you need to pick one of the others (i.e. Google's 8.8.8.8) with the --dns-resolve-method (-r) option. The command therefore becomes:

trip example.com -r google -z

To enable GeoIp information you need a MaxMind GeoIp mmdb database file, which you provide with the --geoip-mmdb-file (-G) option. Note that from Trippy 0.10.x, both MaxMind and IpInfo mmdb files may be used. You can optionally adjust how GeoIp information is displayed with the --tui-geoip-mode option. Therefore, your command could be:

trip example.com --geoip-mmdb-file GeoLite2-City.mmdb --tui-geoip-mode short

To avoid providing these options every time you run Trippy you can set them permanently in a trippy.toml config file.

Combining these, your config file would become:

[dns]
dns-resolve-method = "google"
dns-lookup-as-info = true

[tui]
geoip-mmdb-file = "/path/to/GeoLite2-City.mmdb"
tui-geoip-mode = "short"

Pressing 's' would show up the settings however I don't know how to change them

To confirm that the settings dialog is read-only for the moment, something we aim to improve in the future.

By the way, I can't seem to find "geoip-mmdb-fil" in the settings, do I have to manually add it? Also while trying to use the config I get an UTF-8 Stream error

c-git commented 8 months ago

Are you able to share the file you use to get the stream error here?

Jev1337 commented 8 months ago

image

# Sample config file for Trippy.
#
# Copy this template config file to your platform specific config dir.
#
# Trippy will attempt to locate a `trippy.toml` or `.trippy.toml` config file
# in one of the following locations:
#   the current directory
#   the user home directory
#   the XDG config directory (Unix only): `$XDG_CONFIG_HOME` or `~/.config`
#   the Windows data directory (Windows only): `%APPDATA%`
#
# You may override the config file name and location by passing the `-c`
# (`--config-file`) command line argument.
#
# All sections and all items within each section are non-mandatory.

#
# General Trippy configuration.
#
[trippy]

# The Trippy mode.
#
# Allowed values are:
#   tui         - Display interactive Tui [default]
#   stream      - Display a continuous stream of tracing data
#   pretty      - Generate an pretty text table report for N cycles
#   markdown    - Generate a markdown text table report for N cycles
#   csv         - Generate a CSV report for N cycles
#   json        - Generate a JSON report for N cycles
#   dot         - Generate a Graphviz DOT report for N cycles
#   flows       - Display all flows
#   silent      - Do not generate any output for N cycles
mode = "tui"

# Trace without requiring elevated privileges [default: false]
#
# Enabling will cause IPPROTO_ICMP sockets to be used.
#
# Note: not supported on all platforms.
unprivileged = false

# How to format log data.
#
# Allowed values are:
#  compact      - Display log data in a compact format
#  pretty       - Display log data in a pretty format [default]
#  json         - Display log data in a json format
#  chrome       - Display log data in Chrome trace format
log-format = "pretty"

# The debug log filter [default: trippy=debug]
log-filter = "trippy=debug"

# How to log event spans.
#
# Allowed values are:
#  off          - Do not display event spans [default]
#  active       - Display enter and exit event spans
#  full         - Display all event spans
log-span-events = "off"

#
# Tracing strategy configuration.
#
[strategy]

# The tracing protocol.
#
# Allowed values are:
#   icmp [default]
#   udp
#   tcp
protocol = "icmp"

# The address family.
#
# Allowed values are:
#   ipv4 [default]
#   ipv6
addr-family = "ipv4"

# The target port (TCP & UDP only) [default: 80]
#
# Applicable for TCP and UDP protocols only.
#target-port = 80

# The source port (TCP & UDP only) [default: auto]
#
# Applicable for TCP and UDP protocols only.
#source-port = 1234

# The source IP address [default: auto]
#
# If unspecified the source address will be chosen automatically based on the tracing target.
#source-address = "1.2.3.4"

# The network interface [default: auto]
#
# If not specified the interface is chosen based on the source-address.
#interface = "en0"

# The minimum duration of every round [default: 1s]
#
# The minimum time that must elapse before a tracing round is considered
# complete, regardless of whether the target is discovered or not.
min-round-duration = "1s"

# The maximum duration of every round [default: 1s]
#
# The maximum time that may elapse before a tracing round is considered
# complete, regardless of whether the target is discovered or not.
max-round-duration = "1s"

# The round grace period [default: 100ms]
#
# The period of time to wait for additional probe responses after the target
# has responded.
grace-duration = "100ms"

# The initial sequence number [default: 33000]
initial-sequence = 33000

# The Equal-cost Multi-Path routing strategy (UDP only)
#
# Allowed value are:
#   classic - The src or dest port is used to store the sequence number [default]
#   paris   - The UDP `checksum` field is used to store the sequence number
#   dublin  - The IP `identifier` field is used to store the sequence number
#
# See https://github.com/fujiapple852/trippy/issues/274 for more details.
multipath-strategy = "classic"

# The maximum number of in-flight ICMP echo requests [default: 24]
#
# The tracing strategy operates a sliding window protocol and will allow a
# maximum number of probes to be inflight (sent, and not received or lost)
# at any given time.
max-inflight = 24

# The TTL to start from [default: 1]
first-ttl = 1

# The maximum number of TTL hops [default: 64]
max-ttl = 64

# The size of IP packet to send [default: 84]
#
# For icmp this is the sum of the IP header, ICMP header and the payload.
# Trippy will adjust the size of the payload to fill up to the packet size.
packet-size = 84

# The repeating pattern in the payload of the ICMP packet [default: 0]
payload-pattern = 0

# The TOS IP header value (TCP and UDP only) [default: 0]
#
# This is also known as DSCP+ECN.
tos = 0

# Whether to parse ICMP extensions.
#
# If enabled, all extensions attached to incoming ICMP TimeExceeded and DestinationUnavailable messages will be parsed
# and provided as part of the trace response data.
#
# The following ICMP Extension Object Classes are supported:
#   1 - MPLS Label Stack Class (RFC4950)
#
# Extension objects with an unknown class will be parsed to capture generic information including the class, subtype,
# length and payload bytes.
icmp-extensions = false

# The socket read timeout [default: 10ms]
read-timeout = "10ms"

#
# DNS configuration.
#
[dns]

# How DNS queries are resolved
#
# Allowed values are:
#   system      - Resolve using the OS resolver [default]
#   resolv      - Resolve using the `/etc/resolv.conf` DNS configuration
#   google      - Resolve using the Google `8.8.8.8` DNS service
#   cloudflare  - Resolve using the Cloudflare `1.1.1.1` DNS service
dns-resolve-method = "system"

# Trace to all IPs resolved from DNS lookup (ICMP only) [default: false]
#
# When set to true a trace will be started for all IPs resolved for all given targets.
# When set to false a trace will be started for one arbitrarily chosen IP per given target.
dns-resolve-all = false

# Whether to lookup AS information [default: false]
#
# If enabled, AS (autonomous system) information is retrieved during DNS
# queries.
dns-lookup-as-info = false

# The maximum time to wait to perform DNS queries [default: 5s]
dns-timeout = "5s"

#
# Report generation configuration.
#
[report]

# The number of report cycles to run [default: 10]
#
# Only applicable for modes pretty, markdown, csv and json.
report-cycles = 10

#
# General Tui Configuration.
#
[tui]

# How to render addresses.
#
# Allowed values are:
#   ip - Show IP address only
#   host - Show reverse-lookup DNS hostname only [default]
#   both - Show both IP address and reverse-lookup DNS hostname
tui-address-mode = "host"

# How to render AS information.
#
# Allowed values are:
#   asn             - Show the ASN [default]
#   prefix          - Display the AS prefix
#   country-code    - Display the country code
#   registry        - Display the registry name
#   allocated       - Display the allocated date
#   name            - Display the AS name
tui-as-mode = "asn"

# How to render ICMP extensions
#
#   off             - Do not show icmp extensions [default]
#   mpls            - Show MPLS label(s) only
#   full            - Show full icmp extension data for all known extensions
#   all             - Show full icmp extension data for all classes
tui-icmp-extension-mode = "off"

# How to render GeoIp information.
#
# Allowed values are:
#   off - Do not show GeoIp information [default]
#   short - Show short format GeoIp information
#   long - Show long format GeoIp information
#   location - Show latitude and Longitude format GeoIp information
tui-geoip-mode = "off"

# The maximum number of addresses to show per hop [default: auto]
#
# Use a zero value for `auto`.
tui-max-addrs = 0

# The maximum number of samples to record per hop [default: 256]
tui-max-samples = 256

# The maximum number of flows to show [default: 40]
tui-max-flows = 64

# Whether to preserve the screen on exit [default: false]
tui-preserve-screen = false

# The Tui refresh rate [default: 100ms]
tui-refresh-rate = "100ms"

# The maximum ttl of hops which will be masked for privacy [default: 1]
tui-privacy-max-ttl = 0

# Tui color theme configure.
#
# The allowed colors values are:
#   Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray, DarkGray, LightRed,
#   LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White
#
# Color names are case-insensitive and may contain dashes. Raw hex values,
# such as ffffff for white, may also be used.
#
# See https://github.com/fujiapple852/trippy#theme-reference for details.
[theme-colors]
bg-color = "black"
border-color = "gray"
text-color = "gray"
tab-text-color = "green"
hops-table-header-bg-color = "white"
hops-table-header-text-color = "black"
hops-table-row-active-text-color = "gray"
hops-table-row-inactive-text-color = "darkgray"
hops-chart-selected-color = "green"
hops-chart-unselected-color = "gray"
hops-chart-axis-color = "darkgray"
frequency-chart-bar-color = "green"
frequency-chart-text-color = "gray"
flows-chart-bar-selected-color = "green"
flows-chart-bar-unselected-color = "darkgray"
flows-chart-text-current-color = "lightgreen"
flows-chart-text-non-current-color = "white"
samples-chart-color = "yellow"
help-dialog-bg-color = "blue"
help-dialog-text-color = "gray"
settings-dialog-bg-color = "blue"
settings-tab-text-color = "green"
settings-table-header-text-color = "black"
settings-table-header-bg-color = "white"
settings-table-row-text-color = "gray"
map-world-color = "white"
map-radius-color = "yellow"
map-selected-color = "green"
map-info-panel-border-color = "gray"
map-info-panel-bg-color = "black"
map-info-panel-text-color = "gray"

# Tui key bindings Configuration.
#
# The supported modifiers are: shift, ctrl, alt, super, hyper & meta. Multiple
# modifiers may be specified, for example ctrl+shift+b.
#
# See https://github.com/fujiapple852/trippy#key-bindings-reference for details.
[bindings]
toggle-help = "h"
toggle-help-alt = "?"
toggle-settings = "s"
next-hop = "down"
previous-hop = "up"
next-trace = "right"
previous-trace = "left"
next-hop-address = "."
previous-hop-address = ","
address-mode-ip = "i"
address-mode-host = "n"
address-mode-both = "b"
toggle-freeze = "ctrl+f"
toggle-chart = "c"
toggle-map = "m"
toggle-flows = "f"
toggle-privacy = "p"
expand-hosts = "]"
expand-hosts-max = "}"
contract-hosts = "["
contract-hosts-min = "{"
chart-zoom-in = "="
chart-zoom-out = "-"
clear-trace-data = "ctrl+r"
clear-dns-cache = "ctrl+k"
clear-selection = "esc"
toggle-as-info = "z"
toggle-hop-details = "d"
quit = "q"
c-git commented 8 months ago

@Jev1337 just to confirm you ONLY get this issue if you use the config file?

This config file seems identical to the default and both the default and the one copied work for me. I've uploaded the file I created with what I copied from this post with the .txt extension added as .toml files are not allowed by github. Could you download, remove the .txt extension and try it and let me know if you get the same error please.

trippy.toml.txt

Jev1337 commented 8 months ago

@Jev1337 just to confirm you ONLY get this issue if you use the config file?

This config file seems identical to the default and both the default and the one copied work for me. I've uploaded the file I created with what I copied from this post with the .txt extension added as .toml files are not allowed by github. Could you download, remove the .txt extension and try it and let me know if you get the same error please.

trippy.toml.txt

Yes, I only get this if I use the config file, I remove it, trippy works as expected.

The file you gave me works as expected, however the auto generated template does not work for me.

Path: %APPDATA%

c-git commented 8 months ago

Interesting how do you generate the template? I want to see if I can reproduce the problem.

fujiapple852 commented 8 months ago

Interesting how do you generate the template?

@c-git the template is generated with:

trip --print-config-template

This prints the contents of the trippy-config-sample.toml file that is baked into Trippy to stdout. Note that by baking the configuration file into Trippy we ensure that it matches the version of Trippy, so for example Trippy 0.9.0 has https://github.com/fujiapple852/trippy/blob/0.9.0/trippy-config-sample.toml baked into it.

The --print-config-template simply prints it:

fn print_config_template() {
    println!("{}", include_str!("../trippy-config-sample.toml"));
    process::exit(0);
}

So if the original file is valid utf-8 (it is) then so to will the output. However, I can reproduce the issue in a Windows 11 VM. I'll debug it.

I think what is happening is that the above is outputting UTF-16 LE encoding on Windows and so the file is rejected when later read, as Rust strings must be UTF-8.

fujiapple852 commented 8 months ago

By the way, I can't seem to find "geoip-mmdb-fil" in the settings, do I have to manually add it?

@Jev1337 thanks for pointing this out, it was missing from the trippy-config-sample.toml. This is fixed now and will be correct in Trippy 0.10.0. For now you can just add it manually to the [tui] section:

# The mmdb file to use GeoIp lookup [default: none]
#
# Supported mmdb formats:
#   MaxMind "GeoLite2 City"
#   IPinfo "IP to Country + ASN Database"
#   IPinfo "IP to Geolocation Extended Database"
#geoip-mmdb-file = "/path/to/geoip_file.mmdb"
c-git commented 8 months ago

I think what is happening is that the above is outputting UTF-16 LE encoding on Windows and so the file is rejected when later read, as Rust strings must be UTF-8.

I think one possible solution might be to output directly to a file so the terminal can't mess it up. Either to the home directory or the current directory but I feel like the home directory might be better as I feel more users would want it there and then just output the path to the file. I don't think it's necessarily the best to get rid of the current feature but maybe add one that create a config file like maybe --init-config.

Edit: By home directory I mean the place where trippy would look for it anyway.

Jev1337 commented 8 months ago

@Jev1337 thanks for pointing this out, it was missing from the trippy-config-sample.toml. This is fixed now and will be correct in Trippy 0.10.0.

Glad to be of help! Everything now works as expected!

Interesting how do you generate the template? I want to see if I can reproduce the problem.

As @fujiapple852 said but with redirection, via trip --print-config-template > .toml.

c-git commented 8 months ago

Thank you very much @Jev1337 glad everything works now.

fujiapple852 commented 8 months ago

@Jev1337 @c-git Whilst not strictly a bug, I've added a fix that allows Trippy to read the configuration file in various encodings, including UTF-8 and UTF-16 LE such that it should "just work" on Windows.

See: https://github.com/fujiapple852/trippy/issues/958

Jev1337 commented 8 months ago

@Jev1337 @c-git Whilst not strictly a bug, I've added a fix that allows Trippy to read the configuration file in various encodings, including UTF-8 and UTF-16 LE such that it should "just work" on Windows.

See: #958

I did think of two solutions, either making it read various encodings like you did it or by adding another method that takes a path where to save the configuration file as UTF-8 rather than redirecting the std output to a file (for example --output-template <path>), but good to know that this is no longer a problem!