Terminal bandwidth utilization tool

Overview

bandwhich

demo

This is a CLI utility for displaying current network utilization by process, connection and remote IP/hostname

How does it work?

bandwhich sniffs a given network interface and records IP packet size, cross referencing it with the /proc filesystem on linux, lsof on macOS, or using WinApi on windows. It is responsive to the terminal window size, displaying less info if there is no room for it. It will also attempt to resolve ips to their host name in the background using reverse DNS on a best effort basis.

Installation

Download a prebuilt binary

If you're on linux, you can download the generic binary from the releases.

Arch Linux

pacman -S bandwhich

Nix/NixOS

bandwhich is available in nixpkgs, and can be installed, for example, with nix-env:

nix-env -iA nixpkgs.bandwhich

Void Linux

xbps-install -S bandwhich

Fedora

bandwhich is available in COPR, and can be installed via DNF:

sudo dnf copr enable atim/bandwhich -y && sudo dnf install bandwhich

macOS/Linux (using Homebrew)

brew install bandwhich

FreeBSD

pkg install bandwhich

or

cd /usr/ports/net-mgmt/bandwhich && make install clean

Windows / Other Linux flavours

bandwhich can be installed using the Rust package manager, cargo. It might be in your distro repositories if you're on linux, or you can install it via rustup. You can find additional installation instructions here.

The minimum supported Rust version is 1.39.0.

cargo install bandwhich
On Linux, after installing with cargo:

Cargo installs bandwhich to ~/.cargo/bin/bandwhich but you need root priviliges to run bandwhich. To fix that, there are a few options:

  • Give the executable elevated permissions: sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep $(which bandwhich)
  • Run sudo ~/.cargo/bin/bandwhich instead of just bandwhich
  • Create a symlink: sudo ln -s ~/.cargo/bin/bandwhich /usr/local/bin/ (or another path on root's PATH)
  • Set root's PATH to match your own: sudo env "PATH=$PATH" bandwhich
  • Tell sudo to use your user's environment variables: sudo -E bandwhich
  • Pass the desired target directory to cargo: sudo cargo install bandwhich --root /usr/local/bin/
On Windows, after installing with cargo:

You might need to first install npcap for capturing packets on windows.

OpenWRT

To install bandwhich on OpenWRT, you'll need to compile a binary that would fit its processor architecture. This might mean you would have to cross compile if, for example, you're working on an x86_64 and the OpenWRT is installed on an arm7. Here is an example of cross compiling in this situation:

  • Check the processor architecture of your router by using uname -m
  • Clone the bandwhich repository git clone https://github.com/imsnif/bandwhich
  • Install cross using cargo install cross
  • build the bandwhich package using cross build --target armv7-unknown-linux-musleabihf
  • Copy the binary files from target/armv7-unknown-linux-musleabihf/debug/bandwhich to the router using scp by running scp bandwhich [email protected]:~/ (here, 192.168.1.1 would be the IP address of your router).
  • Finally enter the router using ssh and run the binary directly with ./bandwhich

Usage

USAGE:
    bandwhich [FLAGS] [OPTIONS]

FLAGS:
    -a, --addresses            Show remote addresses table only
    -c, --connections          Show connections table only
    -h, --help                 Prints help information
    -n, --no-resolve           Do not attempt to resolve IPs to their hostnames
    -p, --processes            Show processes table only
    -r, --raw                  Machine friendlier output
    -s, --show-dns             Show DNS queries
    -t, --total-utilization    Show total (cumulative) usages
    -V, --version              Prints version information

OPTIONS:
    -i, --interface <interface>    The network interface to listen on, eg. eth0
    -d, --dns-server <dns-server>    A dns server ip to use instead of the system default

Note that since bandwhich sniffs network packets, it requires root privileges - so you might want to use it with (for example) sudo.

On Linux, you can give the bandwhich binary a permanent capability to use the required privileges, so that you don't need to use sudo bandwhich anymore:

sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep `which bandwhich`

cap_sys_ptrace,cap_dac_read_search gives bandwhich capability to list /proc/<pid>/fd/ and resolve symlinks in that directory. It needs this capability to determine which opened port belongs to which process. cap_net_raw,cap_net_admin gives bandwhich capability to capture packets on your system.

raw_mode

bandwhich also supports an easier-to-parse mode that can be piped or redirected to a file. For example, try:

bandwhich --raw | grep firefox

Contributing

Contributions of any kind are very welcome. If you'd like a new feature (or found a bug), please open an issue or a PR.

To set up your development environment:

  1. Clone the project
  2. cargo run, or if you prefer cargo run -- -i <network interface name> (you can often find out the name with ifconfig or iwconfig). You might need root privileges to run this application, so be sure to use (for example) sudo.

To run tests: cargo test

Note that at the moment the tests do not test the os layer (anything in the os folder).

If you are stuck, unsure about how to approach an issue or would like some guidance, you are welcome to contact: [email protected]

License

MIT

Comments
  • No traffic shown on some macs

    No traffic shown on some macs

    This is 9d93d34d5ab365ec1c07d6ec197cb12c4b8105f3 on macOS 10.14.6 bandwhich starts but shows no traffic. sudo /Users/diver/.cargo/bin/bandwhich

    Screenshot 2019-12-31 at 13 07 14

    sudo /Users/diver/.cargo/bin/bandwhich -i en0 shows the same.

    List of interfaces:

    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
    stf0: flags=0<> mtu 1280
    EHC26: flags=0<> mtu 0
    XHC20: flags=0<> mtu 0
    EHC29: flags=0<> mtu 0
    en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
    awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
    en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
    vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    
    bug 
    opened by diversys 51
  • Add accumlated usage

    Add accumlated usage

    Closes #147

    This works pretty well, but the existing code wasn't really designed for accumulated usage like this, so I've left in some comments where I'd appreciate some others' opinions on refactoring matters.

    This feature really adds a lot to bandwhich for me! I have a metered connection on a server and this PR makes it possible to track down what processes use the most data over a longer period of time!

    This is a draft PR at the moment and I'd be hesitant to merge before we have the chance to address some of the comments I left behind :)

    Additionally, the test snapshots have not been updated yet.

    opened by TheLostLambda 32
  • Failed to find any network interface to listen on

    Failed to find any network interface to listen on

    Hi,

    I played around with bandwhich a bit and stumpled upon the issue, that on some interface it prints:

    sudo bandwhich -i enp216s0f1
    Error: Failed to find any network interface to listen on.
    

    While other interfaces on this system work. The main difference between those interface is that the working one is the onboard NIC and the other one is a dedicated Intel XL710 card with 10GE SFPs connected and is using i40e driver which is also the same as the onboard NIC is using. Other tools like iftop (which I want to replace with bandwhich), tcpdump etc. work on that interface. I also don't see any other error messages. In dmesg I just see the missing output that the interface went into promiscuous mode.

    I also made sure the interface is up. I also tested in on some other machines with dedicated NICs, where I could also see it happen on normal 1GE cooper cards with e1000e driver. But I also had one system where it worked with a dedicated NIC. So I'm a bit lost on how to narrow it down. Any hint would be nice as bandwhich looks like a very nice replacement for the old and slow iftop :)

    The main test system is a debian stretch with kernel 4.19.

    bug 
    opened by norg 28
  • Failing to report unbound UDP traffic

    Failing to report unbound UDP traffic

    I'm not seeing much traffic (basically just ssh and sshd) despite knowing there's a ton of traffic.

    iftop shows me over 20x streams open, but they are all UDP -- freeswitch VoIP streams.

    They are listed in lsof -i

    Is this a bug or by design? I saw no mention in the docs or issues of tcp vs udp.

    Thanks!

    bug 
    opened by avimar 28
  • Issue 163 elapsed time

    Issue 163 elapsed time

    Hi @imsnif,

    I found this project recently and think its great. I have done quite a bit of packet-snooping work in C and C++ and think it's great to see a utility like this in Rust. 😁

    I've started looking into #163 as a first issue to learn more about the program and practice some Rust (new rustacean here). I think I have an implementation working, but it still needs a bit more work to get the tests passing and some cleanup.

    I'd welcome some feedback and maybe some advice about getting these failing tests passing... 😅

    failures:
        tests::cases::ui::basic_only_addresses
        tests::cases::ui::basic_only_connections
        tests::cases::ui::basic_only_processes
        tests::cases::ui::basic_processes_with_dns_queries
        tests::cases::ui::basic_startup
        tests::cases::ui::bi_directional_traffic
        tests::cases::ui::layout_full_width_under_30_height
        tests::cases::ui::layout_under_120_width_full_height
        tests::cases::ui::layout_under_120_width_under_30_height
        tests::cases::ui::multiple_connections_from_remote_address
        tests::cases::ui::multiple_packets_of_traffic_from_different_connections
        tests::cases::ui::multiple_packets_of_traffic_from_single_connection
        tests::cases::ui::multiple_processes_with_multiple_connections
        tests::cases::ui::no_resolve_mode
        tests::cases::ui::one_packet_of_traffic
        tests::cases::ui::one_process_with_multiple_connections
        tests::cases::ui::pause_by_space
        tests::cases::ui::sustained_traffic_from_multiple_processes
        tests::cases::ui::sustained_traffic_from_multiple_processes_bi_directional
        tests::cases::ui::sustained_traffic_from_multiple_processes_bi_directional_total
        tests::cases::ui::sustained_traffic_from_multiple_processes_total
        tests::cases::ui::sustained_traffic_from_one_process
        tests::cases::ui::sustained_traffic_from_one_process_total
        tests::cases::ui::traffic_with_host_names
        tests::cases::ui::traffic_with_winch_event
        tests::cases::ui::truncate_long_hostnames
        tests::cases::ui::two_packets_only_addresses
        tests::cases::ui::two_packets_only_connections
        tests::cases::ui::two_packets_only_processes
        tests::cases::ui::two_windows_split_horizontally
        tests::cases::ui::two_windows_split_vertically
    

    Screen Shot 2020-04-26 at 14 27 49

    Screen Shot 2020-04-26 at 14 28 04

    opened by Eosis 24
  • Release 0.8.0

    Release 0.8.0

    I want to release a new version from master. This one's mostly a lot of infra changes (there's exact info about what's inside in the changelog). A lot of these changes are in untested areas.

    Would love to get some feedback on what's in master right now to make sure it's working. @ebroto, @zhangxp1998 - would you be willing to take it for a short spin?

    discussion 
    opened by imsnif 23
  • cargo install fails on Mac OS Catalina

    cargo install fails on Mac OS Catalina

    Compiling futures v0.3.1 error[E0599]: no method named to_primitive_values found for type pnet_base::MacAddr in the current scope --> /var/folders/32/rk26q2615r31j59ptvscfqpm0000gp/T/cargo-installvKafRX/release/build/pnet_packet-e89ea43c86e9974b/out/ethernet.rs:442:24 | 442 | let vals = val.to_primitive_values(); | ^^^^^^^^^^^^^^^^^^^ method not found in pnet_base::MacAddr

    error[E0599]: no method named to_primitive_values found for type pnet_base::MacAddr in the current scope --> /var/folders/32/rk26q2615r31j59ptvscfqpm0000gp/T/cargo-installvKafRX/release/build/pnet_packet-e89ea43c86e9974b/out/ethernet.rs:499:24 | 499 | let vals = val.to_primitive_values(); | ^^^^^^^^^^^^^^^^^^^ method not found in pnet_base::MacAddr

    Compiling trust-dns-proto v0.18.0-alpha.2 error[E0599]: no method named to_primitive_values found for type pnet_base::MacAddr in the current scope --> /var/folders/32/rk26q2615r31j59ptvscfqpm0000gp/T/cargo-installvKafRX/release/build/pnet_packet-e89ea43c86e9974b/out/arp.rs:776:24 | 776 | let vals = val.to_primitive_values(); | ^^^^^^^^^^^^^^^^^^^ method not found in pnet_base::MacAddr

    error[E0599]: no method named to_primitive_values found for type pnet_base::MacAddr in the current scope --> /var/folders/32/rk26q2615r31j59ptvscfqpm0000gp/T/cargo-installvKafRX/release/build/pnet_packet-e89ea43c86e9974b/out/arp.rs:874:24 | 874 | let vals = val.to_primitive_values(); | ^^^^^^^^^^^^^^^^^^^ method not found in pnet_base::MacAddr

    error: aborting due to 4 previous errors

    For more information about this error, try rustc --explain E0599. error: could not compile pnet_packet. warning: build failed, waiting for other jobs to finish... error: failed to compile bandwhich v0.7.0, intermediate artifacts can be found at /var/folders/32/rk26q2615r31j59ptvscfqpm0000gp/T/cargo-installvKafRX

    Caused by: build failed

    Cargo build works fine, but cargo install fails. Not sure why the difference

    opened by ashpatel 21
  • error: Utf8Error

    error: Utf8Error

    [os] mac os x catalina 10.15.1 [terminal] iTerm2 [shell] zsh [bandwhich version] 0.6.0

    when I run $sudo bandwhich -i en0 get this error

    error: Utf8Error { valid_up_to: 94056, error_len: Some(2) } }', src/libcore/result.rs:1165:5 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

    bug 
    opened by noname2001 21
  • Hide DNS queries by default + provide a CLI flag to override this behaviour

    Hide DNS queries by default + provide a CLI flag to override this behaviour

    Hello! Thanks for such a good tool. I have a question/enhancement: is it possible to ignore some connections in Utilization by connection window? For example, all connections to 53 port. Thanks

    help wanted good first issue 
    opened by alex-bender 18
  • Support Ipv6

    Support Ipv6

    I added code to parse Ipv6 packets and ipv6 addresses from lsof. But the network I'm on does not seem to support ipv6... Can anyone try this for me?

    This is an attempt to resolve issue 53

    opened by zhangxp1998 18
  • error: display_handler panic on launch

    error: display_handler panic on launch

    Immediately after launching, the following error shows up.

    thread 'display_handler' panicked at 'overflow when subtracting durations', src/libcore/option.rs:1185:5
    
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
    
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any', src/libcore/result.rs:1165:5
    
    
    opened by titus-anromedonn 18
  • Feature Request - Filter local addresses

    Feature Request - Filter local addresses

    For example if running "bandwhich -atn" be able to filter for and without private IP ranges.

    This would be useful when trying to track traffic locally or indeed just non local traffic.

    Thanks Rob

    opened by hulleyrob 0
  • Use alternative screen buffer to proper clean up

    Use alternative screen buffer to proper clean up

    Currently exiting bandwhich will break current terminal rendering. I guess it can be improved by the alternative screen feature https://terminalguide.namepad.de/mode/p47/

    opened by amosbird 0
  • Update dependencies to solve build error

    Update dependencies to solve build error

    It seems Rust 64 has created an error when building socket2. This is causing this package to not build.

    To know more, see: https://github.com/NixOS/nixpkgs/pull/194845

    Maybe a cargo update is enough to update the dependencies cache ~but maybe trust-dns-resolver, the dependency bringing socket2 needs an update~.

    Update: I have confirmed that running cargo update fixes the build. Submitting a new version with the updated Cargo.lock should be enough.

    opened by giggio 1
  • Feature Request - choose vertical or horizontal if only showing 2 tables

    Feature Request - choose vertical or horizontal if only showing 2 tables

    Start bandwhich with 'bandwhich -a -c' (only showing connections and remote addresses)

    tables are side by side, would it be possible to add the option to chose under and over as well.

    Thanks

    opened by hulleyrob 0
Releases(0.20.0)
Owner
Aram Drevekenin
Aram Drevekenin
Blazing 💥 fast terminal-ui for git written in rust 🦀

Blazing fast terminal client for git written in Rust Features Fast and intuitive keyboard only control Context based help (no need to memorize tons of

Stephan Dilly 11.8k Jan 5, 2023
Everyday-use client-side map-aware Arch Linux mirror ranking tool

Rate Arch Mirrors This is a tool, which fetches mirrors, skips outdated/syncing Arch Linux mirrors, then uses info about submarine cables and internet

Nikita Almakov 196 Jan 2, 2023
A tool to simplify reprovisioning a fresh OS. Installs packages and manages dotfiles.

[[TOC]] Comtrya This is better, yes? Warning This tool is ridiculously early in its development. I'm building out features as I migrate my dotfiles ov

David McKay 2 Dec 29, 2022
A tool to simplify reprovisioning a fresh OS. Installs packages and manages dotfiles.

Comtrya This is better, yes? Warning This tool is ridiculously early in its development. I'm building out features as I migrate my dotfiles over. Thos

Comtrya 272 Jan 7, 2023
idf-env tool helps set up and manage ESP-IDF installations

idf-env Tool for maintaining ESP-IDF environment. Quick start Install serial drivers for ESP boards on Windows. Execute following command in PowerShel

Espressif Systems 19 Dec 4, 2022
It is a backup tool that creates backups and stores them on an object storage

Hold My Backup It is a backup tool that creates backups and stores them on an object storage. By default it uses minio but you can use AWS: S3 as well

Taylan Dogan 13 Feb 17, 2022
Another tool you didn't know you want

colorful-uname Another tool you didn't know you want Examples: Default operation: "All" operation: Help message: Building and installation: Build proc

S0ra 4 Oct 5, 2022
A tool for quickly switching between different file configurations, using symbolic links.

config-loader A tool for quickly switching between different file configurations, using symbolic links. Usage To use it, download the latest release f

Zacchary Dempsey-Plante 3 Aug 22, 2022
A simple rust-based tool for fetching system information

?? azf a simple rust-based tool for fetching system information you need a patched nerd font and the material design icons font ?? compiling you can c

Pedro Henrique 3 Dec 17, 2022
A network bandwidth and latency tester.

Crusader Network Tester Setup Run cargo build --release to build the executables which are placed in target/release. Command line usage To host a serv

null 29 Dec 25, 2022
Static low-bandwidth search at scale

Pagefind Pagefind is a fully static search library that aims to perform well on large sites, while using as little of your users' bandwidth as possibl

CloudCannon 657 Dec 30, 2022
Github mirror of codeberg repo. Monitor live bandwidth usage/ network speed on PC. Native version also available for Android, separately.

Netspeed Monitor Netspeed is a cross-platform desktop application that shows the live upload speed, download speed and day's usage as an overlay. Feat

Vishnu N K 16 May 3, 2023
Ask the Terminal Anything (ATA): ChatGPT in the terminal

ata: Ask the Terminal Anything ChatGPT in the terminal TIP: Run a terminal with this tool in your background and show/hide it with a keypress. This ca

Rik Huijzer 147 Mar 8, 2023
A terminal ASCII media player. View images, gifs, videos, webcam, YouTube, etc.. directly in the terminal as ASCII art.

Terminal Media Player View images, videos (files or YouTube links), webcam, etc directly in the terminal as ASCII. All images you see below are just m

Max Curzi 36 May 8, 2023
ask.sh: AI terminal assistant that can read and write your terminal directly!

ask.sh: AI terminal assistant that read from & write to your terminal ask.sh is an AI terminal assistant based on OpenAI APIs such as GPT-3.5/4! What'

hmirin 5 Jun 20, 2023
A simple and efficient terminal UI implementation with ratatui.rs for getting quick insights from csv files right on the terminal

CSV-GREP csv-grep is an intuitive TUI application writting with ratatui.rs for reading, viewing and quickly analysing csv files right on the terminal.

Anthony Ezeabasili 16 Mar 10, 2024
nats-spy is a terminal tool to help you to monitor NATS messages.

nats-spy nats-spy is a terminal tool to help you to monitor NATS messages. Install Homebrew (macOS) brew install alihanyalcin/nats-spy/nats-spy Usage

Alihan Doğuş Yalçın 23 Oct 23, 2022
A cli tool to write your idea in terminal

Ideas ideas is a cli tools to write your idea in your terminal. Demo Features tagged idea, contains tips, idea, todo status switch ascii icon write yo

王祎 12 Jun 22, 2022
tai (Terminal Ascii Image) tool to convert images to ascii written in Rust

TAI Terminal Ascii Image A tool to convert images to ascii art written in Rust ?? Notes This tool is still in development stage. Contributions All Con

Mustafa Salih 258 Dec 5, 2022
A minimalist tool for managing block-lists from the terminal.

Block List A minimalist hosts-based tool for managing block lists and ad-blocking. This project uses the excellent and regularly updated Unified Hosts

Oliver Brotchie 7 Aug 14, 2022