60 lines
2.0 KiB
Rust
60 lines
2.0 KiB
Rust
use std::process::exit;
|
|
use std::thread::sleep;
|
|
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;
|
|
mod config;
|
|
mod program;
|
|
|
|
fn main() {
|
|
log("main", "========== PROGRAM START ==========", LogLevel::Info);
|
|
|
|
let network_interface : String;
|
|
|
|
let mut count : i32 = 0;
|
|
loop {
|
|
let interface_str : String = get_active_network_interface().unwrap().trim().to_string();
|
|
|
|
if !interface_str.is_empty() {
|
|
network_interface = interface_str;
|
|
break;
|
|
} else if count >= 10 {
|
|
log("main", "Couldn't find active network card, exiting.", LogLevel::Error);
|
|
exit(1);
|
|
}
|
|
|
|
log("main", "No active network card found, waiting 1 second.", LogLevel::Warn);
|
|
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", "========== PROGRAM END ==========", LogLevel::Info);
|
|
}
|