diff --git a/src/main.rs b/src/main.rs index c7023dd..5237eab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::net::{SocketAddr, IpAddr}; use std::net::TcpStream; -use std::{thread, time}; +use std::{process, thread}; use std::fmt::{Debug}; use std::time::Duration; use chrono::Local; @@ -44,9 +44,13 @@ struct Args { fn main() { let args = Args::parse(); let target_result = get_target_ip(&args.host, &args.v4, &args.v6); + if target_result.is_err() { + println!("Error: {}", target_result.unwrap_err()); + process::exit(0); + } let target_ip: IpAddr = target_result.unwrap(); let delay = chrono::Duration::milliseconds(1000); - let timeout = time::Duration::from_millis(args.timeout.into()); + let timeout = Duration::from_millis(args.timeout.into()); if args.repeat { loop { let start = Local::now(); @@ -54,7 +58,7 @@ fn main() { let end = Local::now(); let delta = end - start; if delta < delay { - thread::sleep((delay-delta).to_std().unwrap()); + thread::sleep((delay - delta).to_std().unwrap()); } } } else { @@ -74,17 +78,15 @@ fn get_target_ip(s: &str, v4: &bool, v6: &bool) -> Result { } else if *v6 && ip.is_ipv6() { return Ok(ip as IpAddr); } - } Err(format!( - "No resolved IPs", + "Failed to Lookup IP", )) } else { Err(format!( - "Target wrong", + "Unable to resolve Address", )) } - } fn ping(host: &IpAddr, port: &u16, timeout: &Duration) -> Result<(), ()> { @@ -96,5 +98,4 @@ fn ping(host: &IpAddr, port: &u16, timeout: &Duration) -> Result<(), ()> { println!("{} - {} - Connection Failed", Local::now().format("%Y-%m-%d %H:%M:%S"), host); Err(()) } - } \ No newline at end of file