diff --git a/Cargo.toml b/Cargo.toml index 4560d34..7d5b4d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ anyhow = "1" log = "0.4" convert-base = "1.1.2" clap = { version = "3.2.16", features = ["derive"] } +cidr-utils = "0.5.7" diff --git a/src/ipv4.rs b/src/ipv4.rs index 043289b..128c181 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -6,12 +6,19 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; #[derive(Debug, Copy, Clone)] pub struct IPv4 { - pub id: u64, + pub id: u64, // u32 pub ip: [u8; 4], } impl IPv4 { pub fn new(id: u64) -> Self { + if id > u32::max_value() as u64 { + panic!( + "IPv4 id is above the IPv4 range! id={id} > {}", + u32::max_value() + ); + } + let mut base = Convert::new(10, 256); let id_vec = util::number_to_vec(id); // push all digits into a vec diff --git a/src/scanner.rs b/src/scanner.rs index ba8e3de..87f4bbc 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -20,10 +20,7 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { } } -fn create_scan_thread( - ip_range: IPv4Range, - target_port: u16, -) -> JoinHandle> { +fn create_scan_thread(ip_range: IPv4Range, target_port: u16) -> JoinHandle> { thread::spawn(move || { let mut results: Vec<(u32, bool)> = Vec::new(); @@ -59,7 +56,7 @@ fn get_scan_workers( num_threads: u64, ignorelist: Option>, ) -> Vec>> { - let ip_amount = to - from; + let ip_amount: u64 = (to as u64 - from as u64) + 1; let ips_per_thread: u64 = ((ip_amount as f32) / num_threads as f32).floor() as u64; // container for all of our threads @@ -77,8 +74,8 @@ fn get_scan_workers( // how many ips we have left after the first threads if (ip_amount as u64 % num_threads) != 0 { - println!(";("); - let ips_left: u64 = ip_amount as u64 - (num_threads * ips_per_thread) as u64; + let completed_ips = (num_threads * ips_per_thread) as u64; + let ips_left: u64 = ip_amount as u64 - completed_ips; // Clean up the rest warn!("Number of IPv4 addresses is not divisible by the amount of threads! Creating extra thread...");