Ref: Überarbeitet Erreichbarkeitsprüfung, ergänzt Unterstützung für HTTP(s)-Zugriffe und verbessert Logging.

This commit is contained in:
2025-08-21 13:37:34 +02:00
parent 176dc27f52
commit b4e1877e36

View File

@@ -24,29 +24,55 @@ pub fn is_reachable(address: &str) -> bool {
#[cfg(target_os = "linux")]
{
let output = Command::new("ping")
.args(["-c", "1", "-W", "2", addr])
.output();
if addr.parse::<Ipv4Addr>().is_ok() {
let output = Command::new("ping")
.args(["-c", "1", "-W", "2", addr])
.output();
if let Ok(out) = output {
out.status.success()
if let Ok(out) = output {
out.status.success()
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
}
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
let output = Command::new("curl")
.args(["--head", "--silent", "--fail", addr])
.output();
if let Ok(out) = output {
out.status.success()
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
}
}
}
#[cfg(target_os = "windows")]
{
let output = Command::new("ping")
.args(["-n", "1", "-w", "2000", addr])
.output();
if addr.parse::<Ipv4Addr>().is_ok() {
let output = Command::new("ping")
.args(["-n", "1", "-w", "2000", addr])
.output();
if let Ok(out) = output {
out.status.success()
if let Ok(out) = output {
out.status.success()
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
}
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
let output = Command::new("powershell")
.args(["-Command", &format!("Invoke-WebRequest -Uri {} -Method HEAD -UseBasicParsing", addr)])
.output();
if let Ok(out) = output {
out.status.success()
} else {
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
false
}
}
}