diff --git a/Cargo.toml b/Cargo.toml index 7d5b4d9..3159141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ log = "0.4" convert-base = "1.1.2" clap = { version = "3.2.16", features = ["derive"] } cidr-utils = "0.5.7" +env_logger = "0.9.0" diff --git a/src/cli.rs b/src/cli.rs index cdc1b3b..47e6d42 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,5 @@ use clap::Parser; -use std::path::PathBuf; +// use std::path::PathBuf; #[derive(Parser, Debug)] #[clap(name = "World Wide Mapping", version, about = "Scan the world wide web for a certian port.", long_about = None)] @@ -15,13 +15,13 @@ pub struct Args { )] pub threads: u64, - #[clap( - help = "A file containing ignored IPv4 addresses (seperated by linebreaks).", - short = 'i', - long = "ignore-ip-list", - default_value = "ignore-ips-list.txt" - )] - pub ignorelist: PathBuf, +// #[clap( +// help = "A file containing ignored IPv4 addresses (seperated by linebreaks).", +// short = 'i', +// long = "ignore-ip-list", +// default_value = "ignore-ips-list.txt" +// )] +// pub ignorelist: PathBuf, #[clap( help = "Enable verbose (debug) output", diff --git a/src/ipv4.rs b/src/ipv4.rs index 998c8a6..e53ace9 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -43,7 +43,7 @@ impl IPv4 { Self { id, ip } } - pub fn to_ipaddr(self: &mut Self) -> Result { + pub fn to_ipaddr(self: &mut Self) -> Result { // TODO: remove unneeded Result returns if let [a, b, c, d] = self.ip[0..4] { Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d))) } else { @@ -57,6 +57,7 @@ impl IPv4 { } } +#[derive(Debug)] pub struct IPv4Range { pub id_start: u32, pub id_end: u32, @@ -68,8 +69,8 @@ impl IPv4Range { let to = to.clamp(0, u32::max_value()); let id_ignore = id_ignore.unwrap_or(Vec::new()); - if from >= to { - panic!("Range size must be >= 1! from={} >= to={}", from, to); + if from > to { + panic!("Range size must be >= 1! from={} > to={}", from, to); } Self { @@ -80,8 +81,10 @@ impl IPv4Range { } pub fn from_cidr(cidr_string: String, id_ignore: Option>) -> Self { - let cidr = Ipv4Cidr::from_str(cidr_string).unwrap(); - let (from, to) = (cidr.first(), cidr.last()); + let cidr = Ipv4Cidr::from_str(cidr_string).unwrap(); + let (from, to) = (cidr.first(), cidr.last()); // TODO: fix forgotten "constants" + + println!("{:?}", cidr.last_as_u8_array()); Self::new(from, to, id_ignore) } diff --git a/src/main.rs b/src/main.rs index b4f6d0f..0e78307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ use ipv4::IPv4Range; use scanner::start_scan; fn main() { - // Get CLI arguments + // Init the logger + env_logger::init(); + + // Get the CLI arguments let args = Args::parse(); // Get the IP range diff --git a/src/scanner.rs b/src/scanner.rs index d953d13..8811095 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,6 +1,6 @@ use crate::ipv4::{IPv4, IPv4Range}; use core::time::Duration; -use log::warn; +use log::{warn, debug, info}; use std::net::TcpStream; use std::thread::JoinHandle; use std::{panic, thread}; @@ -13,9 +13,10 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { let timeout = Duration::new(1, 0); if let Ok(_res) = TcpStream::connect_timeout(&dest, timeout) { - println!("* {:?}", dest); + println!("{:?}", dest); true } else { + debug!("Timeout * {:?}", dest); false } } @@ -23,6 +24,7 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { fn create_scan_thread(ip_range: IPv4Range, target_port: u16) -> JoinHandle> { thread::spawn(move || { let mut results: Vec<(u32, bool)> = Vec::new(); + debug!("Created scan worker for IPv4 range: {:?}", ip_range); // do the scan thing ip_range.into_iter().for_each(|id| { @@ -63,6 +65,7 @@ fn get_scan_workers( let mut threads: Vec>> = Vec::new(); // TODO: make last thread do the "ips_left" work + debug!("Creating scan workers..."); for thread_id in 0..num_threads { let id_ignorelist = range.id_ignore.clone(); @@ -111,7 +114,7 @@ pub fn start_scan(range: IPv4Range, target_port: u16, num_threads: u64) -> Vec = Vec::new(); @@ -130,5 +133,7 @@ pub fn start_scan(range: IPv4Range, target_port: u16, num_threads: u64) -> Vec