Feat: Fügt Funktionen hinzu, um zu testen, ob eine Adresse erreichbar ist.
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -4,6 +4,7 @@ use std::time::Duration;
|
||||
use crate::log::LogLevel;
|
||||
use crate::log::log;
|
||||
use crate::network::network_interface::{get_active_network_interface, get_interface_ip_address};
|
||||
use crate::network::utils::{get_network_address, is_reachable};
|
||||
|
||||
mod log;
|
||||
mod network;
|
||||
@@ -29,12 +30,28 @@ fn main() {
|
||||
count = count+1;
|
||||
sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
log("main", &*format!("Active network interface found: {}", network_interface), LogLevel::Info);
|
||||
|
||||
let interface_address = get_interface_ip_address(network_interface.as_str()).unwrap().trim().to_string();
|
||||
|
||||
log("main", &*format!("Interface address: {}", interface_address), LogLevel::Info);
|
||||
|
||||
let network_address = get_network_address(interface_address.as_str()).unwrap().trim().to_string();
|
||||
log("main", &*format!("Network address: {}", network_address), LogLevel::Info);
|
||||
|
||||
count = 0;
|
||||
loop {
|
||||
if is_reachable(network_address.as_str()) {
|
||||
break;
|
||||
} else if count >= 10 {
|
||||
log("main", "Couldn't reach network address, exiting.", LogLevel::Error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
log("main", "Network address not reachable, waiting 1 second.", LogLevel::Warn);
|
||||
count = count+1;
|
||||
sleep(Duration::from_secs(1));
|
||||
}
|
||||
log("main", "Network address is reachable.", LogLevel::Info);
|
||||
|
||||
log("main", "========== PROGRAMM END ==========", LogLevel::Info);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user