works at console for linux

This commit is contained in:
Trevor Merritt 2025-04-14 09:37:28 -04:00
parent c50857f210
commit ef1d3dde9c
3 changed files with 36 additions and 36 deletions

View File

@ -1,6 +1,6 @@
10.3.100.1
10.13.31.1
10.13.32.1
10.11.31.3
10.12.32.1
10.11.21.1
10.12.22.1
8.8.8.8

View File

@ -1,7 +1,7 @@
10.2.100.1
10.11.21.1
10.12.22.1
10.13.31.1
10.13.32.1
10.11.31.3
10.12.32.1
8.8.8.8
1.1.1.1

View File

@ -12,17 +12,19 @@ use std::time::{Duration, SystemTime};
use ansi_term::Colour::{Green, Red};
use clap::Parser;
use log::{debug, error, log_enabled, info, Level};
#[derive(Clone)]
struct HistoricHost {
pub name: String,
pub address: Ipv4Addr,
pub history: Vec<u128>,
pub alive: bool
pub alive: bool,
}
#[derive(Clone, Debug)]
struct PingResult {
pub address: Ipv4Addr,
pub rtt: u128
pub rtt: u128,
}
impl HistoricHost {
@ -40,7 +42,7 @@ impl HistoricHost {
}
let average_ping_time = running_total.div_ceil(num_results as u128);
println!("Counted {} results, total time {} with average {}",
num_results, running_total, average_ping_time
num_results, running_total, average_ping_time
);
}
@ -65,10 +67,10 @@ impl HistoricHost {
match result {
0 => {
self.history.push(ping_duration.as_millis())
},
}
1 => {
println!("Error ping to {}", self.name);
},
}
_ => {
println!("General Ping Error.");
}
@ -79,7 +81,7 @@ impl HistoricHost {
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct PPArgs {
pub targets: Option<PathBuf>
pub targets: Option<PathBuf>,
}
@ -92,7 +94,6 @@ fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
}
fn main() {
env_logger::init();
let args = PPArgs::parse();
@ -128,9 +129,9 @@ fn main() {
hosts.push(
HistoricHost {
name: target.to_string(),
address: Ipv4Addr::from_str(&target).unwrap_or(Ipv4Addr::new(127,0,0,1)),
address: Ipv4Addr::from_str(&target).unwrap_or(Ipv4Addr::new(127, 0, 0, 1)),
history: vec![],
alive: false
alive: false,
}
)
}
@ -142,25 +143,25 @@ fn main() {
let _ = thread::spawn(move || {
loop {
println!("\x1b[2J --------------");
for current_target in my_hosts.clone() {
// debug!("[MT] Preparing to send off ping request to {}", current_target.address.to_string());
let start_time = SystemTime::now();
for current_target in my_hosts.clone() {
// debug!("[MT] Preparing to send off ping request to {}", current_target.address.to_string());
let start_time = SystemTime::now();
let result = Command::new("/usr/bin/ping").arg(current_target.address.to_string())
.arg("-c 1")
.arg("-4")
.arg("-w 10")
.arg("-W 1")
.output().unwrap().status.code().unwrap_or(255);
let ping_duration = SystemTime::now().duration_since(start_time).unwrap_or(Duration::from_secs(600));
let to_send = if result == 0 {
PingResult { address: current_target.address, rtt: ping_duration.as_millis() }
} else {
PingResult { address: current_target.address, rtt: u128::MAX }
};
let my_sender = sender.clone();
let _ = my_sender.send(to_send);
}
let result = Command::new("/usr/bin/ping").arg(current_target.address.to_string())
.arg("-c 1")
.arg("-4")
.arg("-w 10")
.arg("-W 1")
.output().unwrap().status.code().unwrap_or(255);
let ping_duration = SystemTime::now().duration_since(start_time).unwrap_or(Duration::from_secs(600));
let to_send = if result == 0 {
PingResult { address: current_target.address, rtt: ping_duration.as_millis() }
} else {
PingResult { address: current_target.address, rtt: u128::MAX }
};
let my_sender = sender.clone();
let _ = my_sender.send(to_send);
}
thread::sleep(Duration::from_secs(2));
}
});
@ -176,11 +177,10 @@ fn main() {
let addr = rx.clone().address;
let rtt = rx.clone().rtt;
if rtt == u128::MAX {
// error!("[DT] No reply from {}", addr);
println!("{} not responding", Red.paint(addr.to_string()));
// error!("[DT] No reply from {}", addr);
println!("{} not responding", Red.paint(addr.to_string()));
} else {
// debug!("[DT] Recieved a ping result from {} with time of {}", addr, rtt);
// debug!("[DT] Recieved a ping result from {} with time of {}", addr, rtt);
println!("{} responding.", Green.paint(addr.to_string()));
}
}
@ -190,7 +190,7 @@ fn main() {
info!("Keep Alive Thread Starting.");
let _ = thread::spawn(move || {
let mut counter = 0 ;
let mut counter = 0;
loop {
thread::sleep(Duration::from_millis(1000));
counter += 1;