Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gyulyvgc/listeners
Get processes listening on a TCP port in a cross-platform way
https://github.com/gyulyvgc/listeners
network-programming rust tcp
Last synced: 13 days ago
JSON representation
Get processes listening on a TCP port in a cross-platform way
- Host: GitHub
- URL: https://github.com/gyulyvgc/listeners
- Owner: GyulyVGC
- License: mit
- Created: 2024-02-21T21:04:56.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-07-12T10:48:37.000Z (4 months ago)
- Last Synced: 2024-10-13T17:51:34.020Z (26 days ago)
- Topics: network-programming, rust, tcp
- Language: Rust
- Homepage:
- Size: 149 KB
- Stars: 40
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Listene*rs*
[![Crates](https://img.shields.io/crates/v/listeners?&logo=rust)](https://crates.io/crates/listeners)
[![Downloads](https://img.shields.io/crates/d/listeners.svg)](https://crates.io/crates/listeners)
[![Docs](https://docs.rs/listeners/badge.svg)](https://docs.rs/listeners/latest/)
[![CI](https://github.com/gyulyvgc/listeners/workflows/CI/badge.svg)](https://github.com/GyulyVGC/listeners/actions/)**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](https://crates.io/crates/netstat2): doesn't provide the process name (and it's unmaintained)
- [libproc](https://crates.io/crates/libproc): only for Linux and macOS
- [sysinfo](https://crates.io/crates/sysinfo): doesn't expose the sockets used by each processThis 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
- [x] Windows
- [x] Linux
- [x] macOS
- [ ] BSD
- [ ] iOS
- [ ] Android## Usage
Add this to your `Cargo.toml`:
``` toml
[dependencies]listeners = "0.2"
```Get all the listening processes:
``` rust
if let Ok(listeners) = listeners::get_all() {
for l in listeners {
println!("{l}");
}
}
```Output:
``` text
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`](https://github.com/GyulyVGC/listeners/tree/main/examples) folder.