diff --git a/src/cli.rs b/src/cli.rs index 743f417..eb6545b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,21 +15,14 @@ pub struct Args { )] pub threads: u64, - // #[clap( - // help = "A file containing ignored IPv4 addresses (seperated by linebreaks).", - // short = 'i', - // long = "ignore-ip-list", - // default_value = "ignore-ips-list.txt" - // )] - // pub ignorelist: PathBuf, #[clap( - help = "Enable verbose (debug) output", - short = 'v', - long = "verbose", + help = "Show progress", + short = 'p', + long = "progress", takes_value = false, required = false )] - pub verbose: bool, + pub progress: bool, #[clap( help = "IPv4 subnet range (CIDR). Leave empty for the whole internet.", diff --git a/src/ipv4.rs b/src/ipv4.rs index a13cf9d..0848414 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -85,6 +85,10 @@ impl IPv4Range { Self::new(from, to, id_ignore) } + + pub fn length(self: &Self) -> u32 { + self.id_end - self.id_start + } } impl Iterator for IPv4Range { diff --git a/src/main.rs b/src/main.rs index 33f6247..5fa99c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,5 +24,5 @@ fn main() { let timeout = Duration::new(args.timeout, args.timeout_ns); // Start the scan - let _results = start_scan(range, args.port, args.threads, timeout); + let _results = start_scan(range, args.port, args.threads, timeout, args.progress); } diff --git a/src/scanner.rs b/src/scanner.rs index 6893612..c1ffd2f 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -6,6 +6,7 @@ use std::thread::JoinHandle; use std::{panic, thread}; static mut TCP_SCANS_ISSUED: u64 = 0; +static mut TARGET_SCAN_TOTAL: u32 = 0; fn tcp_scan(mut target: IPv4, target_port: u16, timeout: Duration) -> bool { debug!("Starting scan on {:?}", target); @@ -123,14 +124,39 @@ impl ScanResult { } } +unsafe fn print_progress() { + let percent_done = (TCP_SCANS_ISSUED as f64 / TARGET_SCAN_TOTAL as f64) * 100_f64; + println!("* Progress: {}/{} [{:.2}%]", TCP_SCANS_ISSUED, TARGET_SCAN_TOTAL, percent_done); +} + +fn create_progress_worker() -> JoinHandle<()> { + thread::spawn(move || { + loop { + unsafe { print_progress(); } + + let dur = Duration::new(5, 0); + thread::sleep(dur); + } + }) +} + pub fn start_scan( range: IPv4Range, target_port: u16, num_threads: u64, timeout: Duration, + show_progress: bool, ) -> Vec { println!("Starting wwmap scan..."); + // Create progress worker + unsafe { + if show_progress { + TARGET_SCAN_TOTAL = range.length(); + create_progress_worker(); + } + } + // Get the workers let scan_workers = get_scan_workers(range, target_port, num_threads, timeout); info!("Loaded {} scan worker(s).", scan_workers.len());