|
|
@ -15,7 +15,7 @@ Get default network information |
|
|
|
Add `default-net` to your dependencies |
|
|
|
Add `default-net` to your dependencies |
|
|
|
```toml:Cargo.toml |
|
|
|
```toml:Cargo.toml |
|
|
|
[dependencies] |
|
|
|
[dependencies] |
|
|
|
default-net = "0.4.0" |
|
|
|
default-net = "0.5.0" |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
## Example |
|
|
|
## Example |
|
|
@ -23,16 +23,29 @@ default-net = "0.4.0" |
|
|
|
use default_net; |
|
|
|
use default_net; |
|
|
|
|
|
|
|
|
|
|
|
fn main(){ |
|
|
|
fn main(){ |
|
|
|
if let Some(default_interface) = default_net::get_default_interface(){ |
|
|
|
match default_net::get_default_interface() { |
|
|
|
println!("Index {}", default_interface.index); |
|
|
|
Ok(default_interface) => { |
|
|
|
println!("Name {}", default_interface.name); |
|
|
|
println!("Default Interface"); |
|
|
|
println!("MAC {:?}", default_interface.mac); |
|
|
|
println!("\tIndex: {}", default_interface.index); |
|
|
|
println!("IPv4 {:?}", default_interface.ipv4); |
|
|
|
println!("\tName: {}", default_interface.name); |
|
|
|
println!("IPv6 {:?}", default_interface.ipv6); |
|
|
|
if let Some(mac_addr) = default_interface.mac_addr { |
|
|
|
println!("Gateway IP {:?}", default_interface.gateway.ip); |
|
|
|
println!("\tMAC: {}", mac_addr); |
|
|
|
println!("Gateway MAC {:?}", default_interface.gateway.mac); |
|
|
|
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
println!("Failed to get default interface info"); |
|
|
|
println!("\tMAC: (Failed to get mac address)"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
println!("\tIPv4: {:?}", default_interface.ipv4); |
|
|
|
|
|
|
|
println!("\tIPv6: {:?}", default_interface.ipv6); |
|
|
|
|
|
|
|
if let Some(gateway) = default_interface.gateway { |
|
|
|
|
|
|
|
println!("Default Gateway"); |
|
|
|
|
|
|
|
println!("\tMAC: {}", gateway.mac_addr); |
|
|
|
|
|
|
|
println!("\tIP: {}", gateway.ip_addr); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
println!("Default Gateway: (Not found)"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Err(e) => { |
|
|
|
|
|
|
|
println!("{}", e); |
|
|
|
|
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|