Ref: Überarbeitet Erreichbarkeitsprüfung, ergänzt Unterstützung für HTTP(s)-Zugriffe und verbessert Logging.
This commit is contained in:
@@ -24,6 +24,7 @@ pub fn is_reachable(address: &str) -> bool {
|
|||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
if addr.parse::<Ipv4Addr>().is_ok() {
|
||||||
let output = Command::new("ping")
|
let output = Command::new("ping")
|
||||||
.args(["-c", "1", "-W", "2", addr])
|
.args(["-c", "1", "-W", "2", addr])
|
||||||
.output();
|
.output();
|
||||||
@@ -34,10 +35,23 @@ pub fn is_reachable(address: &str) -> bool {
|
|||||||
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
|
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
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")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
|
if addr.parse::<Ipv4Addr>().is_ok() {
|
||||||
let output = Command::new("ping")
|
let output = Command::new("ping")
|
||||||
.args(["-n", "1", "-w", "2000", addr])
|
.args(["-n", "1", "-w", "2000", addr])
|
||||||
.output();
|
.output();
|
||||||
@@ -48,6 +62,18 @@ pub fn is_reachable(address: &str) -> bool {
|
|||||||
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
|
log::log("network_utils", &*format!("Couldn't reach address {}!", addr), LogLevel::Error);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
|
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
|
||||||
|
|||||||
Reference in New Issue
Block a user