Update README.md

main
shellrow 3 years ago
parent c9fbfc1016
commit 0fa98895ae
  1. 35
      README.md

@ -15,7 +15,7 @@ Get default network information
Add `default-net` to your dependencies
```toml:Cargo.toml
[dependencies]
default-net = "0.4.0"
default-net = "0.5.0"
```
## Example
@ -23,16 +23,29 @@ default-net = "0.4.0"
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");
match default_net::get_default_interface() {
Ok(default_interface) => {
println!("Default Interface");
println!("\tIndex: {}", default_interface.index);
println!("\tName: {}", default_interface.name);
if let Some(mac_addr) = default_interface.mac_addr {
println!("\tMAC: {}", mac_addr);
}else{
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);
},
}
}
```

Loading…
Cancel
Save