prt-core 0.2.0

Core library for prt — real-time network port scanner, tracker and exporter for macOS and Linux
Documentation

prt-core

Crates.io docs.rs License: MIT

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 lsof on macOS or /proc on 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 prt_core::core::scanner;
use prt_core::model::ExportFormat;

let entries = scanner::scan().expect("scan failed");
let json = scanner::export(&entries, ExportFormat::Json).unwrap();
println!("{json}");

Session-based scanning

For continuous monitoring with change tracking:

use prt_core::core::session::Session;

let mut session = Session::new();
session.refresh().expect("refresh failed");

for entry in &session.entries {
    println!("{} :{} ({})", entry.entry.process_name, entry.entry.local_addr.port(), entry.status);
}

i18n

use prt_core::i18n::{set_lang, strings, Lang};

set_lang(Lang::Zh);
let s = strings();
println!("{}", s.app_name); // "PRT"
println!("{}", s.hint_quit); // "退出"

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

License

MIT