From b0ae0b6e702df85c800edd0bbfe54ef8373fed51 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 12 Aug 2022 18:59:53 +0200 Subject: [PATCH] CLI stuff & scanning --- src/cli.rs | 16 ++++++++++++++++ src/main.rs | 5 +++-- src/scanner.rs | 31 +++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e3e63d4..da67d3e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,6 +23,22 @@ pub struct Args { )] pub ignorelist: PathBuf, + #[clap( + help = "From IPv4 -", + short = 'f', + long = "from", + default_value_t = 0 + )] + pub from: u32, + + #[clap( + help = "To IPv4 -", + short = 't', + long = "to", + default_value_t = 4294967295 + )] + pub to: u32, + #[clap( help = "Enable verbose (debug) output", short = 'v', diff --git a/src/main.rs b/src/main.rs index bcaadd5..182b6a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,10 @@ mod util; use clap::Parser; use cli::Args; +use scanner::start_scan; fn main() { - let _args = Args::parse(); + let args = Args::parse(); - //let _results = start_scan(args.port, args.threads as u32, None).unwrap(); + let _results = start_scan(args.from, args.to, args.port, args.threads as u32, None); } diff --git a/src/scanner.rs b/src/scanner.rs index f8ee93f..a21871a 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -41,7 +41,7 @@ fn create_scan_worker( thread_id: u32, ips_per_thread: u32, target_port: u16, - ignorelist: Vec, + ignorelist: Vec ) -> JoinHandle> { let (f, t) = ( (thread_id * ips_per_thread), @@ -51,13 +51,13 @@ fn create_scan_worker( create_scan_thread(thread_id, range, target_port) } -fn start_scan( +fn create_scan_workers( from: u32, to: u32, target_port: u16, num_threads: u32, - ignorelist: Option>, -) -> Result<()> { + ignorelist: Option> +) -> Vec>> { println!("Starting wwmap..."); let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; @@ -74,10 +74,25 @@ fn start_scan( threads.push(worker); } - if ips_left > 0 {} + // Clean up the rest + if ips_left > 0 { + let id_ignorelist = ignorelist.clone().unwrap_or_default(); + threads.push(create_scan_worker(threads.len() as u32 + 1, ips_per_thread, target_port, id_ignorelist)); + } + + threads +} - // container for all the results - let mut result_list: Vec = Vec::new(); +pub fn start_scan( + from: u32, + to: u32, + target_port: u16, + num_threads: u32, + ignorelist: Option> +) { + let threads = create_scan_workers(from, to, target_port, num_threads, ignorelist); - Ok(()) + threads.iter().for_each(|t| { + println!("{t:?}"); + }); }