prt-core
Core library for prt — a real-time network port monitor for macOS and Linux.
What it does
prt-core provides platform-independent logic for:
- Scanning network ports (TCP/UDP) via
lsofon macOS or/procon Linux - Tracking connection changes over time (New → Unchanged → Gone)
- Filtering by port, PID, process name, protocol, state, or user
- Sorting by any column, ascending or descending
- Exporting to JSON or CSV
- Killing processes by PID (SIGTERM / SIGKILL)
- i18n — runtime-switchable localization (English, Russian, Chinese)
Architecture
platform::scan_ports()
→ Session::refresh()
→ scanner::diff_entries() (New / Unchanged / Gone)
→ scanner::sort_entries()
→ scanner::filter_indices()
→ UI renders
| Platform | Method | Performance |
|---|---|---|
| macOS | lsof -F structured output |
2 batch ps calls per cycle |
| Linux | /proc/net/ via procfs crate |
Zero subprocess overhead |
Quick start
use scanner;
use ExportFormat;
let entries = scan.expect;
let json = export.unwrap;
println!;
Session-based scanning
For continuous monitoring with change tracking:
use Session;
let mut session = new;
session.refresh.expect;
for entry in &session.entries
i18n
use ;
set_lang;
let s = strings;
println!; // "PRT"
println!; // "退出"
Language resolution: --lang flag → PRT_LANG env → system locale → English.
Platform support
| OS | Method | Notes |
|---|---|---|
| macOS 10.15+ | lsof -F + batch ps |
Pre-installed, no extra deps |
| Linux | /proc/net/tcp, /proc/net/udp via procfs |
Requires /proc filesystem |