Skip to main content

PortInfo

Struct PortInfo 

Source
pub struct PortInfo {
    pub port: u16,
    pub protocol: Protocol,
    pub pid: u32,
    pub process_name: String,
    pub address: Option<String>,
}
Expand description

Information about a listening port

Fields§

§port: u16

Port number

§protocol: Protocol

Protocol (TCP/UDP)

§pid: u32

Process ID using this port

§process_name: String

Process name

§address: Option<String>

Bind address (e.g., “0.0.0.0”, “127.0.0.1”, “::”)

Implementations§

Source§

impl PortInfo

Source

pub fn get_all_listening() -> Result<Vec<PortInfo>>

Get all listening ports on the system, port ascending and, for one port, PID ascending. The system lists them in its own order (lsof’s on macOS, the kernel’s socket table on Linux, netstat’s on Windows), so the order is fixed here once for everything that reads ports: a process’s ports are ascending in on, for and why, and the holders of a port are by PID.

Source

pub fn holders_of(port: u16) -> Result<Vec<PortInfo>>

Every process listening on a port, each once, PID ascending (empty when nothing listens). One port number can be held by several processes: 127.0.0.1 and [::1] are different sockets.

Source

pub fn get_process(&self) -> Result<Option<Process>>

Get the full process info for this port’s process

Source

pub fn is_exposed(&self) -> bool

Whether the port is open to the network: bound to every address. A port with no known address counts as open.

Source

pub fn is_local(&self) -> bool

Whether the port is bound to loopback only

Trait Implementations§

Source§

impl Clone for PortInfo

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PortInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PortInfo

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PortInfo

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.