#tcp-port #process #tcp-listener #tcp #tcp-socket #port #process-id

listeners

Get processes listening on a TCP port in a cross-platform way

3 unstable releases

0.2.1 Jul 12, 2024
0.2.0 Mar 27, 2024
0.1.0 Mar 14, 2024

#419 in Network programming

Download history 2140/week @ 2024-07-27 2063/week @ 2024-08-03 1520/week @ 2024-08-10 2247/week @ 2024-08-17 3025/week @ 2024-08-24 2652/week @ 2024-08-31 2290/week @ 2024-09-07 2567/week @ 2024-09-14 2202/week @ 2024-09-21 1712/week @ 2024-09-28 1450/week @ 2024-10-05 1089/week @ 2024-10-12 1451/week @ 2024-10-19 1004/week @ 2024-10-26 1160/week @ 2024-11-02 1261/week @ 2024-11-09

5,076 downloads per month
Used in 2 crates

MIT license

46KB
1K SLoC

Listeners

Crates Downloads Docs CI

Rust library to get processes listening on a TCP port in a cross-platform way.

Motivation

Despite some Rust libraries to get process information already exist, none of them satisfies the need to get process ID and name of TCP listeners in a cross-platform way.

Some examples of existing libraries:

  • netstat2: doesn't provide the process name (and it's unmaintained)
  • libproc: only for Linux and macOS
  • sysinfo: doesn't expose the sockets used by each process

This library wants to fill this gap, and it aims to be:

  • Cross-platform: it currently supports Windows, Linux and macOS
  • Performant: it internally uses low-level system APIs
  • Simple: it exposes intuitive APIs to get details about the listening processes
  • Lightweight: it has only the strictly necessary dependencies

Roadmap

  • Windows
  • Linux
  • macOS
  • BSD
  • iOS
  • Android

Usage

Add this to your Cargo.toml:

[dependencies]

listeners = "0.2"

Get all the listening processes:

if let Ok(listeners) = listeners::get_all() {
    for l in listeners {
        println!("{l}");
    }
}

Output:

PID: 1088       Process name: rustrover                 Socket: [::7f00:1]:63342
PID: 609        Process name: Microsoft SharePoint      Socket: [::1]:42050
PID: 160        Process name: mysqld                    Socket: [::]:33060
PID: 160        Process name: mysqld                    Socket: [::]:3306
PID: 460        Process name: rapportd                  Socket: 0.0.0.0:50928
PID: 460        Process name: rapportd                  Socket: [::]:50928 

For more examples of usage, including how to get listening processes in a more granular way, check the examples folder.

Dependencies

~0–39MB
~606K SLoC