net-top is a command-line utility designed to capture and analyze network traffic on a specified interface. It provides real-time statistics about network flows, similar to the functionality of the well-known tool iftop. The application identifies IP addresses, port numbers, and transport protocols to monitor data flow and displays dynamically updated statistics in the terminal.
This project was developed as part of the Network Applications and Network Administration (ISA) course at the Faculty of Information Technology, Brno University of Technology.
- Language: C++
- Packet Capture:
libpcap - Terminal UI:
ncurses - Build System:
Makefile
.
├── include/
│ ├── capture.h # Header for packet capturing and parsing
│ ├── display.h # Header for UI and ncurses functions
│ ├── flow.h # Header for network flow data structures
│ ├── net-top.h # Main application header
│ └── utils.h # Header for utility functions (argument parsing, formatting)
├── src/
│ ├── capture.cpp # Implements packet capturing and L3/L4 parsing
│ ├── display.cpp # Implements the ncurses display logic
│ ├── flow.cpp # Implements network flow management
│ ├── net-top.cpp # Main application logic (main loop, pcap/ncurses init)
│ └── utils.cpp # Implements utility and helper functions
├── tests/ # (Optional) Directory for tests
├── .gitignore # Git ignore file
├── net-top.1 # Man page
├── LICENSE # Project license
├── Makefile # Build script for compiling the project
├── manual.pdf # PDF documentation (in Slovak)
└── README.md # This file```
## Getting Started
Follow these instructions to compile and run the application on a Linux-based system.
### Step 1: Install Prerequisites
Before compiling, you need to install the necessary libraries:
```bash
sudo apt update
sudo apt install build-essential libpcap-dev libncurses5-dev libncursesw5-dev
Clone the repository and go to the project directory. Then, use the provided Makefile to build the executable.
-
Navigate to the source directory:
cd /path/to/net-top -
Compile the project:
make
This will create an executable file named
net-topin the current directory. -
(Optional) Clean build files: To remove the generated object files and the executable, you can run:
make clean
To run the program, you must specify a network interface to monitor. You may need to run the command with sudo.
Basic command structure:
sudo ./net-top -i <interface-id> [-s b|p] [-t <seconds>] [-h|--help]-i <interface-id>: (Required) Specifies the network interface to monitor (e.g.,eth0,wlan0).-s [b|p]: (Optional) Sets the sorting criteria for network flows.b: Sort by total bytes transferred (default).p: Sort by total packets transferred.
-t <seconds>: (Optional) Sets the statistics refresh interval in seconds. Must be greater than 0. The default is 1 second.-hor--help: Displays the help message and exits.
-
Monitor traffic on
wlan0with a 2-second refresh interval:sudo ./net-top -i wlan0 -t 2
-
Monitor traffic on
enp0s3, sorting by packet count with a 5-second interval:sudo ./net-top -i enp0s3 -s p -t 5
-
Display the help message:
./net-top --help
