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
|
||||||
|
|||||||
20
src/main.rs
20
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 {
|
||||||
@ -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,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -178,7 +179,6 @@ fn main() {
|
|||||||
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