From 6d55d96ca75b323a1ff6ee4e5923332926468d2f Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Wed, 23 Apr 2025 15:03:16 -0400 Subject: [PATCH] adds ability to read hosts.txt if no file is specified on the command line, using defaults if hosts.txt is missing --- belleville.txt | 1 + lindsay.txt | 1 + src/bin/pp.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/belleville.txt b/belleville.txt index 8669809..57839c9 100644 --- a/belleville.txt +++ b/belleville.txt @@ -1,3 +1,4 @@ +address,name 10.3.100.1,Belleville Router 10.11.31.3,Belleville VPN 11-31 10.12.32.1,Belleville VPN 12-32 diff --git a/lindsay.txt b/lindsay.txt index 8669809..57839c9 100644 --- a/lindsay.txt +++ b/lindsay.txt @@ -1,3 +1,4 @@ +address,name 10.3.100.1,Belleville Router 10.11.31.3,Belleville VPN 11-31 10.12.32.1,Belleville VPN 12-32 diff --git a/src/bin/pp.rs b/src/bin/pp.rs index 8c6fe3d..30c213d 100644 --- a/src/bin/pp.rs +++ b/src/bin/pp.rs @@ -21,7 +21,6 @@ const SECONDS_IN_MINUTE: u32 = 60; const SECONDS_IN_HOUR: u32 = SECONDS_IN_MINUTE * 60; const SECONDS_IN_DAY: u32 = SECONDS_IN_HOUR * 24; - pub fn duration_to_string(to_convert: Duration) -> String { let mut total_seconds = to_convert.as_secs() as u32; let mut working_string = String::new(); @@ -169,7 +168,15 @@ impl PPState { let settings = AppSettings::parse(); print!("Prep to load targets..."); - let mut targets = PPState::build_targets_from_file(settings.ping_host_file); + let file_to_check = match settings.ping_host_file { + None => { + PathBuf::from("./hosts.txt") + } + Some(actual) => { + actual + } + }; + let mut targets = PPState::build_targets_from_file(Some(file_to_check)); // channel to send requests to ping let (ping_response_sender, ping_response_listener) = mpsc::channel::();