CLI stuff & scanning

main
E. Almqvist 2 years ago
parent 20aec49d15
commit b0ae0b6e70
  1. 16
      src/cli.rs
  2. 5
      src/main.rs
  3. 31
      src/scanner.rs

@ -23,6 +23,22 @@ pub struct Args {
)] )]
pub ignorelist: PathBuf, pub ignorelist: PathBuf,
#[clap(
help = "From IPv4 -",
short = 'f',
long = "from",
default_value_t = 0
)]
pub from: u32,
#[clap(
help = "To IPv4 -",
short = 't',
long = "to",
default_value_t = 4294967295
)]
pub to: u32,
#[clap( #[clap(
help = "Enable verbose (debug) output", help = "Enable verbose (debug) output",
short = 'v', short = 'v',

@ -5,9 +5,10 @@ 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.from, args.to, args.port, args.threads as u32, None);
} }

@ -41,7 +41,7 @@ fn create_scan_worker(
thread_id: u32, thread_id: u32,
ips_per_thread: u32, ips_per_thread: u32,
target_port: u16, target_port: u16,
ignorelist: Vec<u32>, ignorelist: Vec<u32>
) -> JoinHandle<Vec<bool>> { ) -> JoinHandle<Vec<bool>> {
let (f, t) = ( let (f, t) = (
(thread_id * ips_per_thread), (thread_id * ips_per_thread),
@ -51,13 +51,13 @@ fn create_scan_worker(
create_scan_thread(thread_id, range, target_port) create_scan_thread(thread_id, range, target_port)
} }
fn start_scan( fn create_scan_workers(
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<Vec<u32>>
) -> Result<()> { ) -> Vec<JoinHandle<Vec<bool>>> {
println!("Starting wwmap..."); println!("Starting wwmap...");
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;
@ -74,10 +74,25 @@ fn start_scan(
threads.push(worker); threads.push(worker);
} }
if ips_left > 0 {} // Clean up the rest
if ips_left > 0 {
let id_ignorelist = ignorelist.clone().unwrap_or_default();
threads.push(create_scan_worker(threads.len() as u32 + 1, ips_per_thread, target_port, id_ignorelist));
}
// container for all the results threads
let mut result_list: Vec<bool> = Vec::new(); }
Ok(()) pub fn start_scan(
from: u32,
to: u32,
target_port: u16,
num_threads: u32,
ignorelist: Option<Vec<u32>>
) {
let threads = create_scan_workers(from, to, target_port, num_threads, ignorelist);
threads.iter().for_each(|t| {
println!("{t:?}");
});
} }

Loading…
Cancel
Save