reset to old net detection

This commit is contained in:
2025-08-02 12:56:43 +02:00
parent 2177ff0adb
commit bc57076f60

View File

@@ -645,37 +645,8 @@ fn get_disk_info() -> (f64, f64, f64) {
}
fn get_network_traffic() -> Option<(u64, u64)> {
let networks = Networks::new_with_refreshed_list();
if networks.is_empty() {
println!("No network interfaces found.");
return None;
}
println!("Found {} network interfaces.", networks.len());
let mut total_rx = 0;
let mut total_tx = 0;
for (h, data) in &networks {
println!(
"Interface: {}, RX: {}, TX: {}",
h,
data.received(),
data.transmitted()
);
total_rx += data.received();
total_tx += data.transmitted();
}
if total_rx == 0 && total_tx == 0 {
None
} else {
Some((total_rx, total_tx))
}
}
/*
#[cfg(target_os = "windows")]
fn get_network_traffic() -> Option<(u64, u64)> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::shared::ifmib::{MIB_IFROW, MIB_IFTABLE};
use winapi::um::iphlpapi::GetIfTable;
@@ -708,16 +679,20 @@ fn get_network_traffic() -> Option<(u64, u64)> {
tx_total += row.dwOutOctets as u64;
}
Some((rx_total, tx_total))
if rx_total == 0 && tx_total == 0 {
return None;
} else {
return Some((rx_total, tx_total));
}
}
}
}
#[cfg(target_os = "linux")]
fn get_network_traffic() -> Option<(u64, u64)> {
// Bessere Methode mit sysfs
#[cfg(target_os = "linux")]
{
use std::fs;
let mut rx_total = 0u64;
let mut tx_total = 0u64;
if let Ok(dir) = fs::read_dir("/sys/class/net") {
for entry in dir.flatten() {
let iface = entry.file_name();
@@ -736,8 +711,16 @@ fn get_network_traffic() -> Option<(u64, u64)> {
}
}
Some((rx_total, tx_total))
}*/
if rx_total == 0 && tx_total == 0 {
return None;
} else {
return Some((rx_total, tx_total));
}
}
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
None
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {