Cross-platform library to retrieve network sockets information. Aims to be optimal by using low-level OS APIs instead of command line utilities. Provides unified interface and returns data structures which may have additional fields depending on platform.
```rust extern crate netstat;
use netstat::*;
fn main() { let afflags = AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6; let protoflags = ProtocolFlags::TCP | ProtocolFlags::UDP; let socketsinfo = getsocketsinfo(afflags, protoflags).unwrap(); for si in socketsinfo { match si.protocolsocketinfo { ProtocolSocketInfo::Tcp(tcpsi) => println!( "TCP {}:{} -> {}:{} {:?} - {}", tcpsi.localaddr, tcpsi.localport, tcpsi.remoteaddr, tcpsi.remoteport, si.associatedpids, tcpsi.state ), ProtocolSocketInfo::Udp(udpsi) => println!( "UDP {}:{} -> : {:?}", udpsi.localaddr, udpsi.localport, si.associated_pids ), } } } ```
procfs
sysctls
, but currently just parses netstat output (proper impletemention is mostly done in unused modules under src/integrations/osx
folder, it waits for contributors with mac to finish it)Licensed under either of:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.