works at console for linux
This commit is contained in:
parent
c50857f210
commit
ef1d3dde9c
@ -1,6 +1,6 @@
|
|||||||
10.3.100.1
|
10.3.100.1
|
||||||
10.13.31.1
|
10.11.31.3
|
||||||
10.13.32.1
|
10.12.32.1
|
||||||
10.11.21.1
|
10.11.21.1
|
||||||
10.12.22.1
|
10.12.22.1
|
||||||
8.8.8.8
|
8.8.8.8
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
10.2.100.1
|
10.2.100.1
|
||||||
10.11.21.1
|
10.11.21.1
|
||||||
10.12.22.1
|
10.12.22.1
|
||||||
10.13.31.1
|
10.11.31.3
|
||||||
10.13.32.1
|
10.12.32.1
|
||||||
8.8.8.8
|
8.8.8.8
|
||||||
1.1.1.1
|
1.1.1.1
|
||||||
|
|||||||
64
src/main.rs
64
src/main.rs
@ -12,17 +12,19 @@ use std::time::{Duration, SystemTime};
|
|||||||
use ansi_term::Colour::{Green, Red};
|
use ansi_term::Colour::{Green, Red};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use log::{debug, error, log_enabled, info, Level};
|
use log::{debug, error, log_enabled, info, Level};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct HistoricHost {
|
struct HistoricHost {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub address: Ipv4Addr,
|
pub address: Ipv4Addr,
|
||||||
pub history: Vec<u128>,
|
pub history: Vec<u128>,
|
||||||
pub alive: bool
|
pub alive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct PingResult {
|
struct PingResult {
|
||||||
pub address: Ipv4Addr,
|
pub address: Ipv4Addr,
|
||||||
pub rtt: u128
|
pub rtt: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoricHost {
|
impl HistoricHost {
|
||||||
@ -40,7 +42,7 @@ impl HistoricHost {
|
|||||||
}
|
}
|
||||||
let average_ping_time = running_total.div_ceil(num_results as u128);
|
let average_ping_time = running_total.div_ceil(num_results as u128);
|
||||||
println!("Counted {} results, total time {} with average {}",
|
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 {
|
match result {
|
||||||
0 => {
|
0 => {
|
||||||
self.history.push(ping_duration.as_millis())
|
self.history.push(ping_duration.as_millis())
|
||||||
},
|
}
|
||||||
1 => {
|
1 => {
|
||||||
println!("Error ping to {}", self.name);
|
println!("Error ping to {}", self.name);
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("General Ping Error.");
|
println!("General Ping Error.");
|
||||||
}
|
}
|
||||||
@ -79,7 +81,7 @@ impl HistoricHost {
|
|||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct PPArgs {
|
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() {
|
fn main() {
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let args = PPArgs::parse();
|
let args = PPArgs::parse();
|
||||||
@ -128,9 +129,9 @@ fn main() {
|
|||||||
hosts.push(
|
hosts.push(
|
||||||
HistoricHost {
|
HistoricHost {
|
||||||
name: target.to_string(),
|
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![],
|
history: vec![],
|
||||||
alive: false
|
alive: false,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -142,25 +143,25 @@ fn main() {
|
|||||||
let _ = thread::spawn(move || {
|
let _ = thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
println!("\x1b[2J --------------");
|
println!("\x1b[2J --------------");
|
||||||
for current_target in my_hosts.clone() {
|
for current_target in my_hosts.clone() {
|
||||||
// debug!("[MT] Preparing to send off ping request to {}", current_target.address.to_string());
|
// debug!("[MT] Preparing to send off ping request to {}", current_target.address.to_string());
|
||||||
let start_time = SystemTime::now();
|
let start_time = SystemTime::now();
|
||||||
|
|
||||||
let result = Command::new("/usr/bin/ping").arg(current_target.address.to_string())
|
let result = Command::new("/usr/bin/ping").arg(current_target.address.to_string())
|
||||||
.arg("-c 1")
|
.arg("-c 1")
|
||||||
.arg("-4")
|
.arg("-4")
|
||||||
.arg("-w 10")
|
.arg("-w 10")
|
||||||
.arg("-W 1")
|
.arg("-W 1")
|
||||||
.output().unwrap().status.code().unwrap_or(255);
|
.output().unwrap().status.code().unwrap_or(255);
|
||||||
let ping_duration = SystemTime::now().duration_since(start_time).unwrap_or(Duration::from_secs(600));
|
let ping_duration = SystemTime::now().duration_since(start_time).unwrap_or(Duration::from_secs(600));
|
||||||
let to_send = if result == 0 {
|
let to_send = if result == 0 {
|
||||||
PingResult { address: current_target.address, rtt: ping_duration.as_millis() }
|
PingResult { address: current_target.address, rtt: ping_duration.as_millis() }
|
||||||
} else {
|
} else {
|
||||||
PingResult { address: current_target.address, rtt: u128::MAX }
|
PingResult { address: current_target.address, rtt: u128::MAX }
|
||||||
};
|
};
|
||||||
let my_sender = sender.clone();
|
let my_sender = sender.clone();
|
||||||
let _ = my_sender.send(to_send);
|
let _ = my_sender.send(to_send);
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_secs(2));
|
thread::sleep(Duration::from_secs(2));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -176,11 +177,10 @@ fn main() {
|
|||||||
let addr = rx.clone().address;
|
let addr = rx.clone().address;
|
||||||
let rtt = rx.clone().rtt;
|
let rtt = rx.clone().rtt;
|
||||||
if rtt == u128::MAX {
|
if rtt == u128::MAX {
|
||||||
// error!("[DT] No reply from {}", addr);
|
// error!("[DT] No reply from {}", addr);
|
||||||
println!("{} not responding", Red.paint(addr.to_string()));
|
println!("{} not responding", Red.paint(addr.to_string()));
|
||||||
|
|
||||||
} else {
|
} 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()));
|
println!("{} responding.", Green.paint(addr.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ fn main() {
|
|||||||
|
|
||||||
info!("Keep Alive Thread Starting.");
|
info!("Keep Alive Thread Starting.");
|
||||||
let _ = thread::spawn(move || {
|
let _ = thread::spawn(move || {
|
||||||
let mut counter = 0 ;
|
let mut counter = 0;
|
||||||
loop {
|
loop {
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
counter += 1;
|
counter += 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user