Get default network information
default-net
provides a cross-platform API for network interface and gateway.
Add default-net
to your dependencies
toml:Cargo.toml
[dependencies]
default-net = "0.4.0"
```rust use default_net;
fn main(){ if let Some(defaultinterface) = defaultnet::getdefaultinterface(){ println!("Index {}", defaultinterface.index); println!("Name {}", defaultinterface.name); println!("MAC {:?}", defaultinterface.mac); println!("IPv4 {:?}", defaultinterface.ipv4); println!("IPv6 {:?}", defaultinterface.ipv6); println!("Gateway IP {:?}", defaultinterface.gateway.ip); println!("Gateway MAC {:?}", default_interface.gateway.mac); }else{ println!("Failed to get default interface info"); } } ```
For more details, see examples or doc.