bandwhich

repository·main·Indexed 10 days ago

https://github.com/imsnif/bandwhich

A CLI utility for displaying current network utilization by process, connection, and remote IP/hostname. It sniffs network interfaces and cross-references packet sizes with system process information. Version 0.23.1.

Tokens
6.7K
Snippets
37
Records
43
Agent score
95%

What's inside bandwhich

  1. Configure Linux privileges using `setcap`

    main

    Because bandwhich sniffs network packets, it requires elevated privileges. On Linux, the recommended way for single-user machines or trusted environments is to assign specific capabilities to the binary using setcap. This allows unprivileged users to run bandwhich without sudo.

    Required capabilities:

    • cap_sys_ptrace,cap_dac_read_search: Allows access to /proc/<pid>/fd/ to map open ports to processes.
    • cap_net_raw,cap_net_admin: Allows capturing network packets.

    Warning: This setup allows all users to see network traffic, which is not recommended for multi-user environments where privacy is required.

    # assign capabilities
    sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep $(command -v bandwhich)
    
    # run as unprivileged user
    bandwhich
  2. Install bandwhich from source

    main

    To build bandwhich from the source code, clone the repository and use cargo to build the release version. Ensure you have the minimum supported Rust version as specified in the project's Cargo.toml.

    git clone https://github.com/imsnif/bandwhich.git
    cd bandwhich
    cargo build --release
  3. Run bandwhich with `sudo` on Linux

    main

    In multi-user environments, you should run bandwhich using sudo to ensure users cannot monitor others' traffic.

    If bandwhich is installed in a local user directory, sudo might not find it because it doesn't preserve the user's $PATH. You can resolve this by passing the full path or explicitly setting the environment variable.

    # Standard usage
    sudo bandwhich
    
    # If command not found due to PATH issues, use one of these:
    sudo env "PATH=$PATH" bandwhich
    sudo $(command -v bandwhich)