|
|
|
@ -20,12 +20,12 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_scan_thread( |
|
|
|
|
thread_id: u32, |
|
|
|
|
thread_id: u64, |
|
|
|
|
ip_range: IPv4Range, |
|
|
|
|
target_port: u16, |
|
|
|
|
) -> JoinHandle<Vec<(u32, bool)>> { |
|
|
|
|
thread::spawn(move || { |
|
|
|
|
info!("Starting thread worker #{}", thread_id); |
|
|
|
|
info!("Creating thread worker #{}", thread_id); |
|
|
|
|
let mut results: Vec<(u32, bool)> = Vec::new(); |
|
|
|
|
|
|
|
|
|
// do the scan thing
|
|
|
|
@ -40,8 +40,8 @@ fn create_scan_thread( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_scan_worker( |
|
|
|
|
thread_id: u32, |
|
|
|
|
ips_per_thread: u32, |
|
|
|
|
thread_id: u64, |
|
|
|
|
ips_per_thread: u64, |
|
|
|
|
target_port: u16, |
|
|
|
|
ignorelist: Vec<u32>, |
|
|
|
|
) -> JoinHandle<Vec<(u32, bool)>> { |
|
|
|
@ -49,7 +49,7 @@ fn create_scan_worker( |
|
|
|
|
(thread_id * ips_per_thread), |
|
|
|
|
((thread_id + 1) * ips_per_thread), |
|
|
|
|
); |
|
|
|
|
let range = IPv4Range::new(f, t, ignorelist); |
|
|
|
|
let range = IPv4Range::new(f as u32, t as u32, ignorelist); |
|
|
|
|
create_scan_thread(thread_id, range, target_port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -57,13 +57,13 @@ fn get_scan_workers( |
|
|
|
|
from: u32, |
|
|
|
|
to: u32, |
|
|
|
|
target_port: u16, |
|
|
|
|
num_threads: u32, |
|
|
|
|
num_threads: u64, |
|
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
|
) -> Vec<JoinHandle<Vec<(u32, bool)>>> { |
|
|
|
|
println!("Starting wwmap..."); |
|
|
|
|
|
|
|
|
|
let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; |
|
|
|
|
let ips_left = (to - from) - (num_threads * ips_per_thread); // how many ips we have left after the first threads
|
|
|
|
|
let ips_per_thread: u64 = (((to - from) as f32) / num_threads as f32) as u64; |
|
|
|
|
println!("{} : {}", num_threads, ips_per_thread); |
|
|
|
|
let ips_left: u64 = (to - from) as u64 - (num_threads * ips_per_thread) as u64; // how many ips we have left after the first threads
|
|
|
|
|
println!("{} | {}", to - from, 2); |
|
|
|
|
|
|
|
|
|
// container for all of our threads
|
|
|
|
|
let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new(); |
|
|
|
@ -83,7 +83,7 @@ fn get_scan_workers( |
|
|
|
|
warn!("Number of IPv4 addresses is not divisible by the amount of threads! Creating extra thread..."); |
|
|
|
|
let id_ignorelist = ignorelist.clone().unwrap_or_default(); |
|
|
|
|
let worker = create_scan_worker( |
|
|
|
|
threads.len() as u32 + 1, |
|
|
|
|
threads.len() as u64 + 1, |
|
|
|
|
ips_per_thread, |
|
|
|
|
target_port, |
|
|
|
|
id_ignorelist, |
|
|
|
@ -112,21 +112,21 @@ pub fn start_scan( |
|
|
|
|
from: u32, |
|
|
|
|
to: u32, |
|
|
|
|
target_port: u16, |
|
|
|
|
num_threads: u32, |
|
|
|
|
num_threads: u64, |
|
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
|
) -> Vec<ScanResult> { |
|
|
|
|
info!("Starting wwmap scan..."); |
|
|
|
|
|
|
|
|
|
// Get the workers
|
|
|
|
|
debug!("Getting scan workers..."); |
|
|
|
|
println!("Getting scan workers..."); |
|
|
|
|
let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); |
|
|
|
|
debug!("Loaded {} scan worker(s).", scan_workers.len()); |
|
|
|
|
println!("Loaded {} scan worker(s).", scan_workers.len()); |
|
|
|
|
|
|
|
|
|
let mut results: Vec<ScanResult> = Vec::new(); |
|
|
|
|
|
|
|
|
|
// Run all the workers
|
|
|
|
|
for worker in scan_workers { |
|
|
|
|
debug!("* Running worker: {:?}", worker); |
|
|
|
|
println!("* Running worker: {:?}", worker); |
|
|
|
|
let result_tuples = match worker.join() { |
|
|
|
|
Ok(r) => r, |
|
|
|
|
Err(e) => panic!("{:?}", e), |
|
|
|
@ -137,7 +137,7 @@ pub fn start_scan( |
|
|
|
|
.map(|res| ScanResult::from_tuple(*res)) |
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
debug!("\t* Worker got results: {:?}", result_tuples); |
|
|
|
|
println!("\t* Worker got results: {:?}", result_tuples); |
|
|
|
|
results.append(&mut worker_results); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|