|
|
@ -1,6 +1,6 @@ |
|
|
|
use crate::ipv4::{IPv4, IPv4Range}; |
|
|
|
use crate::ipv4::{IPv4, IPv4Range}; |
|
|
|
use core::time::Duration; |
|
|
|
use core::time::Duration; |
|
|
|
use log::info; |
|
|
|
use log::{info, warn, debug}; |
|
|
|
use std::net::TcpStream; |
|
|
|
use std::net::TcpStream; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::{panic, thread}; |
|
|
|
use std::{panic, thread}; |
|
|
@ -80,6 +80,7 @@ fn get_scan_workers( |
|
|
|
|
|
|
|
|
|
|
|
// Clean up the rest
|
|
|
|
// Clean up the rest
|
|
|
|
if ips_left > 0 { |
|
|
|
if ips_left > 0 { |
|
|
|
|
|
|
|
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 id_ignorelist = ignorelist.clone().unwrap_or_default(); |
|
|
|
let worker = create_scan_worker( |
|
|
|
let worker = create_scan_worker( |
|
|
|
threads.len() as u32 + 1, |
|
|
|
threads.len() as u32 + 1, |
|
|
@ -95,16 +96,15 @@ fn get_scan_workers( |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
pub struct ScanResult { |
|
|
|
pub struct ScanResult { |
|
|
|
pub id: u32, |
|
|
|
pub target: IPv4, |
|
|
|
pub ipv4: IPv4, |
|
|
|
|
|
|
|
pub result: bool, |
|
|
|
pub result: bool, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl ScanResult { |
|
|
|
impl ScanResult { |
|
|
|
fn from_tuple(result_tuple: (u32, bool)) -> Self { |
|
|
|
fn from_tuple(result_tuple: (u32, bool)) -> Self { |
|
|
|
let (id, result) = result_tuple; |
|
|
|
let (id, result) = result_tuple; |
|
|
|
let ipv4 = IPv4::new(id as u64); |
|
|
|
let target = IPv4::new(id as u64); |
|
|
|
Self { id, ipv4, result } |
|
|
|
Self { target, result } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -115,15 +115,18 @@ pub fn start_scan( |
|
|
|
num_threads: u32, |
|
|
|
num_threads: u32, |
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
) -> Vec<ScanResult> { |
|
|
|
) -> Vec<ScanResult> { |
|
|
|
// Get the workers
|
|
|
|
info!("Starting wwmap scan..."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the workers
|
|
|
|
|
|
|
|
debug!("Getting scan workers..."); |
|
|
|
let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); |
|
|
|
let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); |
|
|
|
|
|
|
|
debug!("Loaded {} scan worker(s).", scan_workers.len()); |
|
|
|
|
|
|
|
|
|
|
|
let mut results: Vec<ScanResult> = Vec::new(); |
|
|
|
let mut results: Vec<ScanResult> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
// Run all the workers
|
|
|
|
// Run all the workers
|
|
|
|
for worker in scan_workers { |
|
|
|
for worker in scan_workers { |
|
|
|
print!("\t* worker={:?}", worker); |
|
|
|
debug!("* Running worker: {:?}", worker); |
|
|
|
let result_tuples = match worker.join() { |
|
|
|
let result_tuples = match worker.join() { |
|
|
|
Ok(r) => r, |
|
|
|
Ok(r) => r, |
|
|
|
Err(e) => panic!("{:?}", e), |
|
|
|
Err(e) => panic!("{:?}", e), |
|
|
@ -134,11 +137,10 @@ pub fn start_scan( |
|
|
|
.map(|res| ScanResult::from_tuple(*res)) |
|
|
|
.map(|res| ScanResult::from_tuple(*res)) |
|
|
|
.collect(); |
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
//let result = ScanResult::from_tuple(result_tuples);
|
|
|
|
debug!("\t* Worker got results: {:?}", result_tuples); |
|
|
|
results.append(&mut worker_results); |
|
|
|
results.append(&mut worker_results); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
println!("End of scan!"); |
|
|
|
info!("Scan finished!"); |
|
|
|
|
|
|
|
|
|
|
|
results |
|
|
|
results |
|
|
|
} |
|
|
|
} |
|
|
|