uh some optim from f4b3511
This commit is contained in:
+11
-2
@@ -1,10 +1,19 @@
|
||||
use std::collections::HashSet;
|
||||
use std::{collections::HashSet, fs};
|
||||
|
||||
pub fn get_dev() -> HashSet<String> {
|
||||
let mut devs: HashSet<String> = HashSet::new();
|
||||
if let Ok(rd) = std::fs::read_dir("/sys/class/net") {
|
||||
for e in rd.flatten() {
|
||||
if let Ok(name) = e.file_name().into_string()
|
||||
if e.file_type()
|
||||
.map(|ft| {
|
||||
if ft.is_symlink() {
|
||||
fs::metadata(e.path()).map(|m| m.is_dir()).unwrap_or(false)
|
||||
} else {
|
||||
ft.is_dir()
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
&& let Ok(name) = e.file_name().into_string()
|
||||
&& name != "lo"
|
||||
&& !name.is_empty()
|
||||
{
|
||||
|
||||
+2
-2
@@ -58,12 +58,12 @@ pub async fn status_smart_redirect(q: String) -> DeviceQuery {
|
||||
};
|
||||
}
|
||||
// 5) Try DNS: if it resolves, treat as name
|
||||
if tokio::net::lookup_host((s, 0)).await.is_ok() {
|
||||
/* if tokio::net::lookup_host((s, 0)).await.is_ok() {
|
||||
return DeviceQuery {
|
||||
name: Some(s.to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
} */
|
||||
// Default: name last // it will fail also
|
||||
DeviceQuery {
|
||||
name: Some(s.to_string()),
|
||||
|
||||
Reference in New Issue
Block a user