pub struct NetstatClient { /* private fields */ }Expand description
Client for executing netstat commands
This client wraps netstat CLI operations using our CommandExecutor collaborator,
enabling testability and consistency with other external tool clients.
Netstat is a command-line tool that displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
§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::NetstatClient;
let netstat = NetstatClient::new();
// List all TCP listening ports with process information
let output = netstat.list_tcp_listening_ports()?;
println!("Listening ports:\n{}", output);Implementations§
Source§impl NetstatClient
impl NetstatClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new netstat client
§Example
use torrust_tracker_deployer_lib::adapters::network::NetstatClient;
let netstat = NetstatClient::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 netstat -tlnp to list all TCP listening sockets with:
-t: TCP connections only-l: Listening sockets only-n: Numeric addresses (no DNS resolution)-p: Show process ID and name (may require root)
§Returns
The netstat output as a string
§Errors
Returns NetworkError::NetstatFailed if the command fails or netstat is not installed
§Example
let output = netstat.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§
Source§impl Debug for NetstatClient
impl Debug for NetstatClient
Auto Trait Implementations§
impl Freeze for NetstatClient
impl RefUnwindSafe for NetstatClient
impl Send for NetstatClient
impl Sync for NetstatClient
impl Unpin for NetstatClient
impl UnsafeUnpin for NetstatClient
impl UnwindSafe for NetstatClient
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