diff --git a/src/ipv4.rs b/src/ipv4.rs index a0c5b11..c85e69a 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -13,7 +13,7 @@ let i = 0 .. u32:max_value() # This is waaaay better than a stupid loop */ -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct IPv4 { pub id: u64, pub ip: Vec, @@ -72,9 +72,7 @@ pub fn get_all(ignorelist: Option>) -> Result> { let mut ip = IPv4::new(ip as u64); // Make the IP "ignored" if it is in the ignorelist - if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { - ip.ignore = true; - } + ip.ignore = ignorelist.contains(&ip.id); ip }) diff --git a/src/scanner.rs b/src/scanner.rs index ed126ae..a6343d5 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,5 +1,5 @@ use crate::ipv4; -use anyhow::{Result, anyhow}; +use anyhow::Result; use log::info; use std::thread; use std::{ @@ -7,7 +7,7 @@ use std::{ thread::JoinHandle, }; -async fn tcp_scan(dest: &SocketAddr) -> bool { +fn tcp_scan(dest: &SocketAddr) -> bool { if let Ok(res) = TcpStream::connect(dest) { info!("Got TCP ack from: {:?}", dest); return true; @@ -15,23 +15,32 @@ async fn tcp_scan(dest: &SocketAddr) -> bool { false } -pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Vec) -> Result<()> { - let ip_list = ipv4::get_all(None)?; +pub fn scan(target: &ipv4::IPv4) -> bool { + true +} + +pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Option>) -> Result<()> { + let ip_list = ipv4::get_all(ignorelist)?; // casting hell - // Get the amount of needed threads - let needed_threads = ((ip_list.len() as f32) / num_threads as f32).ceil() as u32; + let ips_per_thread = ((ip_list.len() 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 // Container for all of our threads let mut threads: Vec> = Vec::new(); // Create all of our threads - for i in 0..needed_threads { - let thread = thread::spawn(|| { - // do scan - let target = ip_list[i as usize].to_socketaddr(target_port)?; - }); - threads.push(thread); + for thread_id in 0..num_threads { + threads.push( + thread::spawn(move || { + // do the scan thing + for i in 0..ips_per_thread { + let id = (thread_id * ips_per_thread) + i; + let ref target = ip_list[id as usize]; + let result = scan(&target); + } + }) + ); } Ok(())