From d13364fc45a7c574d1482e2b8d7b6481f8f8dcf9 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 12 Aug 2022 19:26:48 +0200 Subject: [PATCH] Fixed errors --- src/cli.rs | 7 +------ src/ipv4.rs | 4 ++-- src/scanner.rs | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index da67d3e..3e12767 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,12 +23,7 @@ pub struct Args { )] pub ignorelist: PathBuf, - #[clap( - help = "From IPv4 -", - short = 'f', - long = "from", - default_value_t = 0 - )] + #[clap(help = "From IPv4 -", short = 'f', long = "from", default_value_t = 0)] pub from: u32, #[clap( diff --git a/src/ipv4.rs b/src/ipv4.rs index c4e4076..0283f40 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -41,10 +41,10 @@ impl IPv4 { } pub fn to_ipaddr(self: &mut Self) -> Result { - if let [a, b, c, d] = self.ip[0..3] { + if let [a, b, c, d] = self.ip[0..4] { Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d))) } else { - Err(anyhow!("Unable to unpack IPv4 address")) + Err(anyhow!("Unable to unpack IPv4 address: {:?}", self.ip)) } } diff --git a/src/scanner.rs b/src/scanner.rs index a21871a..7fe98ba 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,12 +1,14 @@ use crate::ipv4::{IPv4, IPv4Range}; use anyhow::Result; use log::info; -use std::net::TcpStream; +use std::net::{SocketAddr, TcpStream}; use std::thread; use std::thread::JoinHandle; fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { - let dest = target.to_socketaddr(target_port).unwrap(); + let _dest = target + .to_socketaddr(target_port) + .unwrap_or_else(|e| panic!("{}", e)); false // TODO: FIX @@ -30,7 +32,7 @@ fn create_scan_thread( ip_range.into_iter().for_each(|id| { let target = IPv4::new(id as u64); let result = tcp_scan(target, target_port); - results.insert(id as usize, result); + results.push(result); }); results @@ -41,7 +43,7 @@ fn create_scan_worker( thread_id: u32, ips_per_thread: u32, target_port: u16, - ignorelist: Vec + ignorelist: Vec, ) -> JoinHandle> { let (f, t) = ( (thread_id * ips_per_thread), @@ -56,7 +58,7 @@ fn create_scan_workers( to: u32, target_port: u16, num_threads: u32, - ignorelist: Option> + ignorelist: Option>, ) -> Vec>> { println!("Starting wwmap..."); @@ -77,7 +79,12 @@ fn create_scan_workers( // 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)); + threads.push(create_scan_worker( + threads.len() as u32 + 1, + ips_per_thread, + target_port, + id_ignorelist, + )); } threads @@ -88,7 +95,7 @@ pub fn start_scan( to: u32, target_port: u16, num_threads: u32, - ignorelist: Option> + ignorelist: Option>, ) { let threads = create_scan_workers(from, to, target_port, num_threads, ignorelist);