pub struct NetworkData { /* private fields */ }Expand description
Getting volume of received and transmitted data.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("[{}] {network:?}", interface_name.display());
}
}Implementations§
Source§impl NetworkData
impl NetworkData
Sourcepub fn received(&self) -> u64
pub fn received(&self) -> u64
Returns the number of received bytes since the last refresh.
If you want the total number of bytes received, take a look at the
total_received method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("in: {} B", network.received());
}
}Sourcepub fn total_received(&self) -> u64
pub fn total_received(&self) -> u64
Returns the total number of received bytes.
If you want the amount of received bytes since the last refresh, take a look at the
received method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("in: {} B", network.total_received());
}
}Sourcepub fn transmitted(&self) -> u64
pub fn transmitted(&self) -> u64
Returns the number of transmitted bytes since the last refresh.
If you want the total number of bytes transmitted, take a look at the
total_transmitted method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("out: {} B", network.transmitted());
}
}Sourcepub fn total_transmitted(&self) -> u64
pub fn total_transmitted(&self) -> u64
Returns the total number of transmitted bytes.
If you want the amount of transmitted bytes since the last refresh, take a look at the
transmitted method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("out: {} B", network.total_transmitted());
}
}Sourcepub fn packets_received(&self) -> u64
pub fn packets_received(&self) -> u64
Returns the number of incoming packets since the last refresh.
If you want the total number of packets received, take a look at the
total_packets_received method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("in: {}", network.packets_received());
}
}Sourcepub fn total_packets_received(&self) -> u64
pub fn total_packets_received(&self) -> u64
Returns the total number of incoming packets.
If you want the amount of received packets since the last refresh, take a look at the
packets_received method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("in: {}", network.total_packets_received());
}
}Sourcepub fn packets_transmitted(&self) -> u64
pub fn packets_transmitted(&self) -> u64
Returns the number of outcoming packets since the last refresh.
If you want the total number of packets transmitted, take a look at the
total_packets_transmitted method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("out: {}", network.packets_transmitted());
}
}Sourcepub fn total_packets_transmitted(&self) -> u64
pub fn total_packets_transmitted(&self) -> u64
Returns the total number of outcoming packets.
If you want the amount of transmitted packets since the last refresh, take a look at the
packets_transmitted method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("out: {}", network.total_packets_transmitted());
}
}Sourcepub fn errors_on_received(&self) -> u64
pub fn errors_on_received(&self) -> u64
Returns the number of incoming errors since the last refresh.
If you want the total number of errors on received packets, take a look at the
total_errors_on_received method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("in: {}", network.errors_on_received());
}
}Sourcepub fn total_errors_on_received(&self) -> u64
pub fn total_errors_on_received(&self) -> u64
Returns the total number of incoming errors.
If you want the amount of errors on received packets since the last refresh, take a look at
the errors_on_received method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("in: {}", network.total_errors_on_received());
}
}Sourcepub fn errors_on_transmitted(&self) -> u64
pub fn errors_on_transmitted(&self) -> u64
Returns the number of outcoming errors since the last refresh.
If you want the total number of errors on transmitted packets, take a look at the
total_errors_on_transmitted method.
use sysinfo::Networks;
use std::{thread, time};
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);
for (interface_name, network) in &networks {
println!("out: {}", network.errors_on_transmitted());
}
}Sourcepub fn total_errors_on_transmitted(&self) -> u64
pub fn total_errors_on_transmitted(&self) -> u64
Returns the total number of outcoming errors.
If you want the amount of errors on transmitted packets since the last refresh, take a look at
the errors_on_transmitted method.
use sysinfo::Networks;
if let Ok(networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("out: {}", network.total_errors_on_transmitted());
}
}Sourcepub fn mac_address(&self) -> MacAddr
pub fn mac_address(&self) -> MacAddr
Returns the MAC address associated to current interface.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("MAC address: {}", network.mac_address());
}
}Sourcepub fn ip_networks(&self) -> &[IpNetwork]
pub fn ip_networks(&self) -> &[IpNetwork]
Returns the Ip Networks associated to current interface.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("Ip Networks: {:?}", network.ip_networks());
}
}Sourcepub fn mtu(&self) -> u64
pub fn mtu(&self) -> u64
Returns the Maximum Transfer Unit (MTU) of the interface.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("mtu: {}", network.mtu());
}
}Sourcepub fn transmit_link_speed(&self) -> Option<u64>
pub fn transmit_link_speed(&self) -> Option<u64>
Returns the transmit link speed of the interface in bits per second.
For Ethernet interfaces, this is the negotiated link speed.
For Wi-Fi interfaces, this is the link speed reported by the OS.
Returns the same value as Self::receive_link_speed on Unix systems.
Returns None when the link speed is not available.
For example, when the interface is down or when the driver does not provide a link speed.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("transmit link speed: {:?}", network.transmit_link_speed());
}
}Sourcepub fn receive_link_speed(&self) -> Option<u64>
pub fn receive_link_speed(&self) -> Option<u64>
Returns the receive link speed of the interface in bits per second.
For Ethernet interfaces, this is the negotiated link speed.
For Wi-Fi interfaces, this is the link speed reported by the OS.
Returns the same value as Self::transmit_link_speed on Unix systems.
Returns None when the link speed is not available.
For example, when the interface is down or when the driver does not provide a link speed.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("receive link speed: {:?}", network.receive_link_speed());
}
}Sourcepub fn operational_state(&self) -> InterfaceOperationalState
pub fn operational_state(&self) -> InterfaceOperationalState
Returns the operational state of the interface.
The operational state indicates whether the interface is able to pass packets or not.
For details on the individual states see the documentation of the InterfaceOperationalState enum and its variants.
use sysinfo::Networks;
if let Ok(mut networks) = Networks::new_with_refreshed_list() {
for (interface_name, network) in &networks {
println!("operational state: {}", network.operational_state());
}
}