From 98e56dd1b53ec3a11b031900834f61aee178b202 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 8 Aug 2022 21:23:13 +0200 Subject: [PATCH] Stuff --- src/scanner.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/scanner.rs b/src/scanner.rs index 988e487..ed126ae 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,4 +1,5 @@ use crate::ipv4; +use anyhow::{Result, anyhow}; use log::info; use std::thread; use std::{ @@ -6,7 +7,7 @@ use std::{ thread::JoinHandle, }; -async fn check_ack(dest: &SocketAddr) -> bool { +async fn tcp_scan(dest: &SocketAddr) -> bool { if let Ok(res) = TcpStream::connect(dest) { info!("Got TCP ack from: {:?}", dest); return true; @@ -14,18 +15,26 @@ async fn check_ack(dest: &SocketAddr) -> bool { false } -pub fn start_scan(depth: u32) { - let ip_list = ipv4::get_all(None); +pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Vec) -> Result<()> { + let ip_list = ipv4::get_all(None)?; + // casting hell + // Get the amount of needed threads + let needed_threads = ((ip_list.len() as f32) / num_threads as f32).ceil() as u32; + + // Container for all of our threads let mut threads: Vec> = Vec::new(); - for i in 0..depth { + // Create all of our threads + for i in 0..needed_threads { let thread = thread::spawn(|| { - println!("hi"); // do scan + let target = ip_list[i as usize].to_socketaddr(target_port)?; }); threads.push(thread); } + + Ok(()) } /*