pub struct Adapter { /* private fields */ }
Expand description
Represent an adapter.
Implementations§
source§impl Adapter
impl Adapter
sourcepub fn adapter_name(&self) -> &str
pub fn adapter_name(&self) -> &str
Get the adapter’s name
sourcepub fn ip_addresses(&self) -> &[IpAddr]
pub fn ip_addresses(&self) -> &[IpAddr]
Get the adapter’s ip addresses (unicast ip addresses)
Examples found in repository?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let mut adapters = ipconfig::get_adapters().unwrap();
adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
for adapter in adapters {
println!(
"{}: IfType: {:?} IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
adapter.friendly_name(),
adapter.if_type(),
adapter.ip_addresses(),
adapter.ipv4_metric(),
adapter.ipv6_metric()
)
}
}
sourcepub fn prefixes(&self) -> &[(IpAddr, u32)]
pub fn prefixes(&self) -> &[(IpAddr, u32)]
Get the adapter’s prefixes. Returns a list of tuples (IpAddr, u32), where first element is a subnet address, e.g. 192.168.1.0 and second element is prefix length, e.g. 24
sourcepub fn dns_servers(&self) -> &[IpAddr]
pub fn dns_servers(&self) -> &[IpAddr]
Get the adapter’s dns servers (the preferred dns server is first)
sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Get the adapter’s description
sourcepub fn friendly_name(&self) -> &str
pub fn friendly_name(&self) -> &str
Get the adapter’s friendly name
Examples found in repository?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let mut adapters = ipconfig::get_adapters().unwrap();
adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
for adapter in adapters {
println!(
"{}: IfType: {:?} IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
adapter.friendly_name(),
adapter.if_type(),
adapter.ip_addresses(),
adapter.ipv4_metric(),
adapter.ipv6_metric()
)
}
}
sourcepub fn physical_address(&self) -> Option<&[u8]>
pub fn physical_address(&self) -> Option<&[u8]>
Get the adapter’s physical (MAC) address
sourcepub fn receive_link_speed(&self) -> u64
pub fn receive_link_speed(&self) -> u64
Get the adapter Recieve Link Speed (bits per second)
sourcepub fn transmit_link_speed(&self) -> u64
pub fn transmit_link_speed(&self) -> u64
Get the Trasnmit Link Speed (bits per second)
sourcepub fn oper_status(&self) -> OperStatus
pub fn oper_status(&self) -> OperStatus
Check if the adapter is up (OperStatus is IfOperStatusUp)
sourcepub fn if_type(&self) -> IfType
pub fn if_type(&self) -> IfType
Get the interface type
Examples found in repository?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let mut adapters = ipconfig::get_adapters().unwrap();
adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
for adapter in adapters {
println!(
"{}: IfType: {:?} IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
adapter.friendly_name(),
adapter.if_type(),
adapter.ip_addresses(),
adapter.ipv4_metric(),
adapter.ipv6_metric()
)
}
}
sourcepub fn ipv6_if_index(&self) -> u32
pub fn ipv6_if_index(&self) -> u32
Get the IPv6 interface index.
The return value can be used as an IPv6 scope id for link-local addresses.
sourcepub fn ipv4_metric(&self) -> u32
pub fn ipv4_metric(&self) -> u32
Returns the metric used to compute route preference for IPv4
Examples found in repository?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let mut adapters = ipconfig::get_adapters().unwrap();
adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
for adapter in adapters {
println!(
"{}: IfType: {:?} IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
adapter.friendly_name(),
adapter.if_type(),
adapter.ip_addresses(),
adapter.ipv4_metric(),
adapter.ipv6_metric()
)
}
}
sourcepub fn ipv6_metric(&self) -> u32
pub fn ipv6_metric(&self) -> u32
Returns the metric used to compute route preference for IPv6
Examples found in repository?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let mut adapters = ipconfig::get_adapters().unwrap();
adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
for adapter in adapters {
println!(
"{}: IfType: {:?} IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
adapter.friendly_name(),
adapter.if_type(),
adapter.ip_addresses(),
adapter.ipv4_metric(),
adapter.ipv6_metric()
)
}
}