(rust) reading interface addresses

This commit is contained in:
scbj
2025-06-25 09:52:42 +02:00
parent 1acb77331b
commit b86e403814
+9 -25
View File
@@ -1,8 +1,8 @@
#![allow(dead_code, unused)]
use std::{
use chrono::{DateTime, Local};
use tokio::{
fs,
path::PathBuf,
};
use dirs::config_dir;
@@ -11,30 +11,14 @@ const TIMEOUT_LIMIT: usize = 32;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut path: PathBuf = match config_dir() {
Some(value) => value,
None => return Err(anyhow::Error::msg("no configuration directory for you")),
};
let mut interfaces = fs::read_dir("/sys/class/net").await?;
check_path(&path);
path.push("navigate");
check_path(&path);
path.push("bookmarks");
check_path(&path);
path.push("default.toml");
check_path(&path);
while let Ok(Some(interface)) = interfaces.next_entry().await {
let if_name = interface.file_name().into_string().unwrap();
if !(if_name == "lo") && !if_name.contains("loop") {
println!("name: {}", if_name);
}
}
Ok(())
}
fn check_path(path: &PathBuf) {
if path.is_dir() {
println!("[{:#?}] is a valid `DIRECTORY`", path);
} else if path.is_file() {
println!("[{:#?}] is a valid `FILE`", path);
} else if path.exists() {
println!("[{:#?}] is a valid `ENTITY`", path);
} else {
println!("[{:#?}] is `NOT` a valid path", path);
}
}