More refactoring

main
E. Almqvist 2 years ago
parent 0ead50c0c7
commit 3154903bec
  1. 6
      src/ipv4.rs
  2. 6
      src/main.rs
  3. 37
      src/scanner.rs

@ -61,8 +61,8 @@ pub struct IPv4Range {
} }
impl IPv4Range { impl IPv4Range {
pub fn new(from: u32, to: u32, id_ignore: Option<Vec<u32>>) -> Self { pub fn new(from: u32, to: u32, id_ignore: &mut Vec<u32>) -> Self {
to = to.clamp(0, u32::max_value()); let to = to.clamp(0, u32::max_value());
if from >= to { if from >= to {
panic!("Range size must be >= 1! from: {} >= to: {}", from, to); panic!("Range size must be >= 1! from: {} >= to: {}", from, to);
@ -71,7 +71,7 @@ impl IPv4Range {
Self { Self {
id_start: from, id_start: from,
id_end: to, id_end: to,
id_ignore: id_ignore.unwrap_or(Vec::new()), id_ignore
} }
} }
} }

@ -6,10 +6,8 @@ mod util;
use clap::Parser; use clap::Parser;
use cli::Args; use cli::Args;
use scanner::start_scan;
fn main() { fn main() {
let args = Args::parse(); let _args = Args::parse();
let _results = start_scan(args.port, args.threads as u32, None).unwrap(); //let _results = start_scan(args.port, args.threads as u32, None).unwrap();
} }

@ -37,35 +37,50 @@ fn create_scan_thread(
}) })
} }
pub fn start_scan( fn create_scan_worker(
thread_id: u32,
ips_per_thread: u32,
target_port: u16,
ignorelist: &mut Vec<u32>,
) -> JoinHandle<Vec<bool>> {
let (f, t) = (
(thread_id * ips_per_thread),
((thread_id + 1) * ips_per_thread),
);
let range = IPv4Range::new(f, t, ignorelist);
create_scan_thread(thread_id, range, target_port)
}
fn start_scan(
from: u32, from: u32,
to: u32, to: u32,
target_port: u16, target_port: u16,
num_threads: u32, num_threads: u32,
ignorelist: Option<Vec<u32>>, ignorelist: Option<&mut Vec<u32>>,
) -> Result<()> { ) -> Result<()> {
println!("Starting wwmap..."); println!("Starting wwmap...");
//let ip_list = get_all(ignorelist)?;
let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32;
let ips_left = num_threads * ips_per_thread; // 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
// container for all of our threads // container for all of our threads
let mut threads: Vec<JoinHandle<Vec<bool>>> = Vec::new(); let mut threads: Vec<JoinHandle<Vec<bool>>> = Vec::new();
for thread_id in 0..num_threads { for thread_id in 0..num_threads {
// Calculate ranges & stuff let thread_ignorelist = ignorelist.unwrap_or(&mut Vec::new());
let (f, t) = (
(thread_id * ips_per_thread),
((thread_id + 1) * ips_per_thread),
);
let range = IPv4Range::new(f, t, ignorelist);
// Create a worker // Create a worker
let worker = create_scan_thread(thread_id, range, target_port); let worker = create_scan_worker(
thread_id,
ips_per_thread,
target_port,
thread_ignorelist
);
threads.push(worker); threads.push(worker);
} }
if ips_left > 0 {}
// container for all the results // container for all the results
let mut result_list: Vec<bool> = Vec::new(); let mut result_list: Vec<bool> = Vec::new();

Loading…
Cancel
Save