(rust) reading interface addresses
This commit is contained in:
+9
-25
@@ -1,8 +1,8 @@
|
|||||||
#![allow(dead_code, unused)]
|
#![allow(dead_code, unused)]
|
||||||
|
|
||||||
use std::{
|
use chrono::{DateTime, Local};
|
||||||
|
use tokio::{
|
||||||
fs,
|
fs,
|
||||||
path::PathBuf,
|
|
||||||
};
|
};
|
||||||
use dirs::config_dir;
|
use dirs::config_dir;
|
||||||
|
|
||||||
@@ -11,30 +11,14 @@ const TIMEOUT_LIMIT: usize = 32;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let mut path: PathBuf = match config_dir() {
|
let mut interfaces = fs::read_dir("/sys/class/net").await?;
|
||||||
Some(value) => value,
|
|
||||||
None => return Err(anyhow::Error::msg("no configuration directory for you")),
|
|
||||||
};
|
|
||||||
|
|
||||||
check_path(&path);
|
while let Ok(Some(interface)) = interfaces.next_entry().await {
|
||||||
path.push("navigate");
|
let if_name = interface.file_name().into_string().unwrap();
|
||||||
check_path(&path);
|
if !(if_name == "lo") && !if_name.contains("loop") {
|
||||||
path.push("bookmarks");
|
println!("name: {}", if_name);
|
||||||
check_path(&path);
|
}
|
||||||
path.push("default.toml");
|
}
|
||||||
check_path(&path);
|
|
||||||
|
|
||||||
Ok(())
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user