Added progress flag

main
E. Almqvist 2 years ago
parent 1fab779a60
commit 2dc81f16ad
  1. 15
      src/cli.rs
  2. 4
      src/ipv4.rs
  3. 2
      src/main.rs
  4. 26
      src/scanner.rs

@ -15,21 +15,14 @@ pub struct Args {
)] )]
pub threads: u64, 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( #[clap(
help = "Enable verbose (debug) output", help = "Show progress",
short = 'v', short = 'p',
long = "verbose", long = "progress",
takes_value = false, takes_value = false,
required = false required = false
)] )]
pub verbose: bool, pub progress: bool,
#[clap( #[clap(
help = "IPv4 subnet range (CIDR). Leave empty for the whole internet.", help = "IPv4 subnet range (CIDR). Leave empty for the whole internet.",

@ -85,6 +85,10 @@ impl IPv4Range {
Self::new(from, to, id_ignore) Self::new(from, to, id_ignore)
} }
pub fn length(self: &Self) -> u32 {
self.id_end - self.id_start
}
} }
impl Iterator for IPv4Range { impl Iterator for IPv4Range {

@ -24,5 +24,5 @@ fn main() {
let timeout = Duration::new(args.timeout, args.timeout_ns); let timeout = Duration::new(args.timeout, args.timeout_ns);
// Start the scan // 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);
} }

@ -6,6 +6,7 @@ use std::thread::JoinHandle;
use std::{panic, thread}; use std::{panic, thread};
static mut TCP_SCANS_ISSUED: u64 = 0; 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 { fn tcp_scan(mut target: IPv4, target_port: u16, timeout: Duration) -> bool {
debug!("Starting scan on {:?}", target); 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( pub fn start_scan(
range: IPv4Range, range: IPv4Range,
target_port: u16, target_port: u16,
num_threads: u64, num_threads: u64,
timeout: Duration, timeout: Duration,
show_progress: bool,
) -> Vec<ScanResult> { ) -> Vec<ScanResult> {
println!("Starting wwmap scan..."); println!("Starting wwmap scan...");
// Create progress worker
unsafe {
if show_progress {
TARGET_SCAN_TOTAL = range.length();
create_progress_worker();
}
}
// Get the workers // Get the workers
let scan_workers = get_scan_workers(range, target_port, num_threads, timeout); let scan_workers = get_scan_workers(range, target_port, num_threads, timeout);
info!("Loaded {} scan worker(s).", scan_workers.len()); info!("Loaded {} scan worker(s).", scan_workers.len());

Loading…
Cancel
Save