diff --git a/src/cli.rs b/src/cli.rs index 3e12767..6348c71 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -30,7 +30,7 @@ pub struct Args { help = "To IPv4 -", short = 't', long = "to", - default_value_t = 4294967295 + default_value_t = u32::max_value() )] pub to: u32, diff --git a/src/main.rs b/src/main.rs index 182b6a8..b08ff68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,5 +10,7 @@ use scanner::start_scan; fn main() { let args = Args::parse(); - let _results = start_scan(args.from, args.to, args.port, args.threads as u32, None); + let results = start_scan(args.from, args.to, args.port, args.threads as u32, None); + + for result in results { println!("{:?}", result); } } diff --git a/src/scanner.rs b/src/scanner.rs index c3e4fe6..884bac6 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,5 +1,6 @@ use crate::ipv4::{IPv4, IPv4Range}; use log::info; +use core::time::Duration; use std::net::TcpStream; use std::thread::JoinHandle; use std::{panic, thread}; @@ -9,7 +10,9 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { .to_socketaddr(target_port) .unwrap_or_else(|e| panic!("{}", e)); - if let Ok(res) = TcpStream::connect(dest) { + let timeout = Duration::new(1, 0); + + if let Ok(res) = TcpStream::connect_timeout(&dest, timeout) { info!("* Got TCP ack from: {:?} | {:?}", dest, res); return true; } @@ -65,6 +68,7 @@ fn get_scan_workers( // container for all of our threads let mut threads: Vec>> = Vec::new(); + // TODO: make last thread do the "ips_left" work for thread_id in 0..num_threads { let id_ignorelist = ignorelist.clone().unwrap_or_default(); @@ -98,19 +102,26 @@ pub fn start_scan( ) -> Vec> { // Get the workers + println!("Getting workers.."); let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); let mut results: Vec> = Vec::new(); // Run all the workers + println!("Running workers:"); for worker in scan_workers { + print!("\t* worker={:?}", worker); let result = match worker.join() { Ok(r) => r, Err(e) => panic!("{:?}", e) }; + println!(" result={:?}", result); + results.push(result); } + println!("End of scan!"); + results }