fork of https://github.com/shellrow/default-net/tree/v0.16.2 fixes an unsafe bug in sockaddr_to_network_addr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shellrow c9fbfc1016 Bump version to 0.5.0 3 years ago
examples Performance improvement, Refactoring 3 years ago
src Performance improvement, Refactoring 3 years ago
.gitignore Update .gitignore 3 years ago
Cargo.toml Bump version to 0.5.0 3 years ago
LICENSE Initial commit 4 years ago
README.md Update README.md 3 years ago

README.md

default-net Crates.io License

Get default network information
default-net provides a cross-platform API for network interface and gateway.

Supported platform

  • Linux
  • macOS
  • Windows

Usage

Add default-net to your dependencies

[dependencies]
default-net = "0.4.0"

Example

use default_net;

fn main(){
    if let Some(default_interface) = default_net::get_default_interface(){
        println!("Index {}", default_interface.index);
        println!("Name {}", default_interface.name);
        println!("MAC {:?}", default_interface.mac);
        println!("IPv4 {:?}", default_interface.ipv4);
        println!("IPv6 {:?}", default_interface.ipv6);
        println!("Gateway IP {:?}", default_interface.gateway.ip);
        println!("Gateway MAC {:?}", default_interface.gateway.mac);
    }else{
        println!("Failed to get default interface info");
    }
}

For more details, see examples or doc.