pub struct SsClient { /* private fields */ }Expand description
Client for executing ss (socket statistics) commands
This client wraps ss CLI operations using our CommandExecutor collaborator,
enabling testability and consistency with other external tool clients.
SS is a modern utility to investigate sockets and is the replacement for netstat. It’s faster and provides more detailed information about network connections.
§Architecture
The client uses CommandExecutor as a collaborator for actual command execution,
following the same pattern as other adapters in this crate.
§Example
use torrust_tracker_deployer_lib::adapters::network::SsClient;
let ss = SsClient::new();
// List all TCP listening ports with process information
let output = ss.list_tcp_listening_ports()?;
println!("Listening ports:\n{}", output);Implementations§
Source§impl SsClient
impl SsClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ss client
§Example
use torrust_tracker_deployer_lib::adapters::network::SsClient;
let ss = SsClient::new();Sourcepub fn list_tcp_listening_ports(&self) -> Result<String, NetworkError>
pub fn list_tcp_listening_ports(&self) -> Result<String, NetworkError>
List TCP listening ports with process information
Executes ss -tlnp to list all TCP listening sockets with:
-t: TCP sockets only-l: Listening sockets only-n: Numeric addresses (no DNS resolution)-p: Show process information (may require root)
§Returns
The ss output as a string
§Errors
Returns NetworkError::SsFailed if the command fails or ss is not installed
§Example
let output = ss.list_tcp_listening_ports()?;
// Parse output to find specific ports
for line in output.lines() {
if line.contains(":8080") {
println!("Port 8080 is in use: {}", line);
}
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for SsClient
impl RefUnwindSafe for SsClient
impl Send for SsClient
impl Sync for SsClient
impl Unpin for SsClient
impl UnsafeUnpin for SsClient
impl UnwindSafe for SsClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request