main
E. Almqvist 2 years ago
parent 1d84950db3
commit 3856c3ce3b
  1. 2
      src/cli.rs
  2. 2
      src/main.rs
  3. 32
      src/scanner.rs

@ -13,7 +13,7 @@ pub struct Args {
long = "threads", long = "threads",
default_value_t = 1 default_value_t = 1
)] )]
pub threads: u8, pub threads: u64,
#[clap( #[clap(
help = "A file containing ignored IPv4 addresses (seperated by linebreaks).", help = "A file containing ignored IPv4 addresses (seperated by linebreaks).",

@ -10,7 +10,7 @@ use scanner::start_scan;
fn main() { fn main() {
let args = Args::parse(); 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, None);
for result in results { for result in results {
println!("{:?}", result); println!("{:?}", result);

@ -20,12 +20,12 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool {
} }
fn create_scan_thread( fn create_scan_thread(
thread_id: u32, thread_id: u64,
ip_range: IPv4Range, ip_range: IPv4Range,
target_port: u16, target_port: u16,
) -> JoinHandle<Vec<(u32, bool)>> { ) -> JoinHandle<Vec<(u32, bool)>> {
thread::spawn(move || { thread::spawn(move || {
info!("Starting thread worker #{}", thread_id); info!("Creating thread worker #{}", thread_id);
let mut results: Vec<(u32, bool)> = Vec::new(); let mut results: Vec<(u32, bool)> = Vec::new();
// do the scan thing // do the scan thing
@ -40,8 +40,8 @@ fn create_scan_thread(
} }
fn create_scan_worker( fn create_scan_worker(
thread_id: u32, thread_id: u64,
ips_per_thread: u32, ips_per_thread: u64,
target_port: u16, target_port: u16,
ignorelist: Vec<u32>, ignorelist: Vec<u32>,
) -> JoinHandle<Vec<(u32, bool)>> { ) -> JoinHandle<Vec<(u32, bool)>> {
@ -49,7 +49,7 @@ fn create_scan_worker(
(thread_id * ips_per_thread), (thread_id * ips_per_thread),
((thread_id + 1) * 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) create_scan_thread(thread_id, range, target_port)
} }
@ -57,13 +57,13 @@ fn get_scan_workers(
from: u32, from: u32,
to: u32, to: u32,
target_port: u16, target_port: u16,
num_threads: u32, num_threads: u64,
ignorelist: Option<Vec<u32>>, ignorelist: Option<Vec<u32>>,
) -> Vec<JoinHandle<Vec<(u32, bool)>>> { ) -> Vec<JoinHandle<Vec<(u32, bool)>>> {
println!("Starting wwmap..."); let ips_per_thread: u64 = (((to - from) as f32) / num_threads as f32) as u64;
println!("{} : {}", num_threads, ips_per_thread);
let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; 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
let ips_left = (to - from) - (num_threads * ips_per_thread); // how many ips we have left after the first threads println!("{} | {}", to - from, 2);
// container for all of our threads // container for all of our threads
let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new(); 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..."); 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 u64 + 1,
ips_per_thread, ips_per_thread,
target_port, target_port,
id_ignorelist, id_ignorelist,
@ -112,21 +112,21 @@ pub fn start_scan(
from: u32, from: u32,
to: u32, to: u32,
target_port: u16, target_port: u16,
num_threads: u32, num_threads: u64,
ignorelist: Option<Vec<u32>>, ignorelist: Option<Vec<u32>>,
) -> Vec<ScanResult> { ) -> Vec<ScanResult> {
info!("Starting wwmap scan..."); info!("Starting wwmap scan...");
// Get the workers // Get the workers
debug!("Getting scan workers..."); println!("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()); println!("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 {
debug!("* Running worker: {:?}", worker); println!("* 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),
@ -137,7 +137,7 @@ pub fn start_scan(
.map(|res| ScanResult::from_tuple(*res)) .map(|res| ScanResult::from_tuple(*res))
.collect(); .collect();
debug!("\t* Worker got results: {:?}", result_tuples); println!("\t* Worker got results: {:?}", result_tuples);
results.append(&mut worker_results); results.append(&mut worker_results);
} }

Loading…
Cancel
Save