A high-performance Linux CLI/TUI application that monitors network traffic in real-time, showing active connections, bandwidth usage per application, and traffic visualization. Built with Rust for maximum performance and memory safety.
- Real-time Packet Capture: Captures all network packets using libpcap with BPF filter support
- Protocol Parsing: Full support for TCP, UDP, ICMP over IPv4 and IPv6
- Process Association: Maps network connections to running processes using
/procfilesystem - Bandwidth Tracking: Real-time bandwidth calculation per connection and per process
- Terminal UI: Beautiful, interactive TUI with multiple views
- Overview: System-wide statistics including total bandwidth, active connections, packet counts
- Process View: List of processes sorted by bandwidth usage, connection count, or name
- Connection View: Detailed list of all active network connections with process mapping
- Filtering: Filter traffic by process name, PID, port, protocol, or IP range
- Data Export: Export snapshots to JSON or CSV for analysis
- Real-time Updates: Configurable refresh interval for live monitoring
- Low Overhead: Efficient packet processing with minimal system impact
- Operating System: Linux (kernel 2.6+)
- Architecture: x86_64, ARM64
- Privileges: Root access or
CAP_NET_RAWcapability
- Rust: 1.70 or later
- libpcap: Development headers
Debian/Ubuntu:
sudo apt-get update
sudo apt-get install libpcap-dev build-essentialFedora/RHEL/CentOS:
sudo dnf install libpcap-devel gccArch Linux:
sudo pacman -S libpcap base-devel- Clone the repository:
git clone https://github.com/yourusername/Real-Time-Network-Analyzer.git
cd Real-Time-Network-Analyzer- Build the project:
cargo build --release- Install the binary:
sudo cp target/release/netflow /usr/local/bin/- Set capabilities (optional, to run without sudo):
sudo setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/netflowRun with default settings (requires root):
sudo netflowNetFlow - Real-time Network Traffic Analyzer
Usage: netflow [OPTIONS]
Options:
-i, --interface <INTERFACE> Network interface to monitor (e.g., eth0, wlan0)
-p, --promiscuous Enable promiscuous mode
-f, --filter <FILTER> BPF filter expression
-e, --export <FILE> Export to file (JSON or CSV)
-r, --refresh <MS> Refresh interval in milliseconds [default: 1000]
-d, --debug Enable debug logging
-h, --help Print help
-V, --version Print version
Monitor specific interface:
sudo netflow -i eth0Monitor with BPF filter (only HTTPS traffic):
sudo netflow -f "tcp port 443"Export snapshot after 60 seconds:
sudo netflow -e /tmp/traffic.jsonMonitor with faster refresh rate:
sudo netflow -r 500Debug mode:
sudo netflow -dWhen running in TUI mode:
| Key | Action |
|---|---|
Tab |
Next tab |
Shift+Tab |
Previous tab |
↑ / ↓ |
Navigate lists |
b |
Sort by bandwidth |
n |
Sort by name |
c |
Sort by connection count |
q |
Quit |
netflow/
├── src/
│ ├── capture/ # Packet capture using libpcap
│ ├── parser/ # Protocol parsers (TCP/UDP/ICMP)
│ ├── process/ # Process-to-socket mapping
│ ├── aggregator/ # Traffic statistics & state management
│ ├── ui/ # Terminal UI with ratatui
│ ├── filter/ # Traffic filtering engine
│ ├── export/ # JSON/CSV export
│ └── main.rs # Application entry point
├── Cargo.toml
└── README.md
Raw Packets (libpcap)
↓
Protocol Parser (Ethernet → IP → TCP/UDP)
↓
Connection Tracker (5-tuple)
↓
Process Resolver (/proc/net/tcp, /proc/{pid}/fd)
↓
Traffic Aggregator (bandwidth calculation)
↓
Terminal UI / Export
- Packet Capture: Uses libpcap to capture raw packets from network interface
- Parsing: Extracts connection information (5-tuple: src_ip, src_port, dst_ip, dst_port, protocol)
- Process Mapping:
- Reads
/proc/net/tcpand/proc/net/udpto get socket inodes - Scans
/proc/{pid}/fd/to map inodes to PIDs - Retrieves process names from
/proc/{pid}/stat
- Reads
- Aggregation: Calculates bandwidth over time windows (1s, 5s)
- Display: Updates TUI with real-time statistics
- Packet Processing: ~100K packets/second on modern hardware
- Memory Usage: ~50MB base + ~1KB per active connection
- CPU Usage: ~5-10% on single core at moderate traffic levels
- Linux Only: Uses Linux-specific
/procfilesystem - Root Required: Packet capture requires elevated privileges
- Local System Only: Cannot monitor remote systems directly
- Short-lived Connections: May miss very brief connections (< 1 second)
Error: Failed to open capture device
Solution: Run with sudo or set capabilities:
sudo setcap cap_net_raw,cap_net_admin=eip /path/to/netflowActive Connections: 0
Solution:
- Verify interface is correct:
ip link show - Check for existing BPF filters
- Ensure traffic is actually flowing
Solution:
- Some processes may restrict
/procaccess - Short-lived connections may close before process is resolved
- Try running with higher privileges
Solution:
- Increase refresh interval:
-r 2000 - Apply BPF filter to reduce packet volume
- Ensure release build:
cargo build --release
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Run tests
cargo test
# Run with logging
RUST_LOG=debug cargo run -- -dThe codebase is modular and extensible:
- New protocols: Extend
parser/mod.rs - Additional filters: Add to
filter/mod.rs - Export formats: Implement in
export/mod.rs - UI improvements: Modify
ui/mod.rs
- GeoIP integration for location mapping
- Real-time graphs and sparklines
- DNS resolution for remote addresses
- Historical data analysis
- Alert system for unusual traffic
- Web dashboard
- Docker container support
- Packet capture file (pcap) analysis mode
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
This project is licensed under the MIT License - see LICENSE file for details.
- Built with libpcap for packet capture
- UI powered by ratatui
- Inspired by iftop, nethogs, and bandwhich
This tool requires elevated privileges to capture network traffic. Always:
- Review the source code before running
- Only monitor networks you own or have permission to monitor
- Be aware that packet capture can expose sensitive data
- Use appropriate filtering to minimize privacy concerns
For bugs, feature requests, or questions:
- Open an issue on GitHub
- Check existing issues for solutions
- Include debug output when reporting problems
Note: This is a monitoring tool for legitimate network analysis. Unauthorized network monitoring may be illegal in your jurisdiction.