A real-time network traffic monitoring script for macOS Terminal that displays internet traffic with per-second rates, process tracking, and interactive controls.
- Real-time monitoring - Updates every 2 seconds showing current network activity
- Process-based tracking - Monitors traffic by process name with current PID display
- Internet-only traffic - Filters out localhost and local network traffic (192.168.x.x, 10.x.x.x, etc.)
- Historical tracking - Maintains cumulative traffic statistics across process restarts
- Interactive sorting - Sort by process name, total traffic, or current rates
- Dead process tracking - Option to show/hide processes that are no longer active
- Color-coded display - Easy-to-read color formatting with highlighted sort columns
- macOS (uses
nettopcommand) - Terminal with color support
- zsh shell (default on modern macOS)
- Make the script executable:
chmod +x netmon.sh- Run the script:
./netmon.shThe script displays network traffic in a table format with the following columns:
| Column | Description |
|---|---|
| PROCESS (PID) | Process name with current Process ID |
| IN (MB) | Total data received (cumulative) |
| OUT (MB) | Total data sent (cumulative) |
| IN/s | Current incoming data rate (KB/s) |
| OUT/s | Current outgoing data rate (KB/s) |
Example showing various processes with their network activity. Notice how mDNSResponder has the highest cumulative traffic, while com.apple.WebKit shows active incoming traffic.
<or,- Sort by previous column>or.- Sort by next columndorD- Toggle display of dead processesCtrl+C- Exit the monitor
- Active processes - Shown in normal text with current rates
- Dead processes - Shown in dim text with dashes for rates (when enabled)
- Sort indicator - Current sort column is highlighted in cyan
- Status line - Shows current time, controls, and dead process toggle state
- Summary row - Displays totals and count of alive/dead processes
- Data Collection: Uses macOS
nettopcommand to gather network statistics - Filtering: Excludes local network traffic (localhost, LAN addresses)
- Process Aggregation: Groups traffic by process name, tracking across PID changes
- Rate Calculation: Computes per-second rates from periodic samples
- Persistent Tracking: Maintains history in temporary files for session duration
- Update Interval: 2 seconds for data refresh
- Poll Interval: 0.1 seconds for keyboard input
- Maximum Rows: 20 processes displayed at once
- Minimum Traffic: Shows all processes with any network activity
- Cleanup: Automatically removes temporary files on exit
- Ensure you have network activity (try browsing the web)
- Check that
nettopcommand is available and working - The script shows all processes with any network activity
- The script uses standard macOS commands and doesn't require special permissions
- If you encounter issues, try running from a different terminal or restarting Terminal.app
- Ensure your terminal supports ANSI color codes
- Most modern terminals (Terminal.app, iTerm2) support colors by default
The script creates a temporary directory in /tmp/netmon.XXXXXX/ during operation containing:
prev- Previous readings for rate calculationhistory- Process history and cumulative statisticscurr- Current nettop output processing
All temporary files and the directory are automatically cleaned up when the script exits.
Created for monitoring internet traffic on macOS systems with a focus on clarity and ease of use.
This script is provided as-is for educational and monitoring purposes.
