Fixed errors

main
E. Almqvist 2 years ago
parent b0ae0b6e70
commit d13364fc45
  1. 7
      src/cli.rs
  2. 4
      src/ipv4.rs
  3. 21
      src/scanner.rs

@ -23,12 +23,7 @@ pub struct Args {
)] )]
pub ignorelist: PathBuf, pub ignorelist: PathBuf,
#[clap( #[clap(help = "From IPv4 -", short = 'f', long = "from", default_value_t = 0)]
help = "From IPv4 -",
short = 'f',
long = "from",
default_value_t = 0
)]
pub from: u32, pub from: u32,
#[clap( #[clap(

@ -41,10 +41,10 @@ impl IPv4 {
} }
pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> { pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> {
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))) Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d)))
} else { } else {
Err(anyhow!("Unable to unpack IPv4 address")) Err(anyhow!("Unable to unpack IPv4 address: {:?}", self.ip))
} }
} }

@ -1,12 +1,14 @@
use crate::ipv4::{IPv4, IPv4Range}; use crate::ipv4::{IPv4, IPv4Range};
use anyhow::Result; use anyhow::Result;
use log::info; use log::info;
use std::net::TcpStream; use std::net::{SocketAddr, TcpStream};
use std::thread; use std::thread;
use std::thread::JoinHandle; use std::thread::JoinHandle;
fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { 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 false
// TODO: FIX // TODO: FIX
@ -30,7 +32,7 @@ fn create_scan_thread(
ip_range.into_iter().for_each(|id| { ip_range.into_iter().for_each(|id| {
let target = IPv4::new(id as u64); let target = IPv4::new(id as u64);
let result = tcp_scan(target, target_port); let result = tcp_scan(target, target_port);
results.insert(id as usize, result); results.push(result);
}); });
results results
@ -41,7 +43,7 @@ fn create_scan_worker(
thread_id: u32, thread_id: u32,
ips_per_thread: u32, ips_per_thread: u32,
target_port: u16, target_port: u16,
ignorelist: Vec<u32> ignorelist: Vec<u32>,
) -> JoinHandle<Vec<bool>> { ) -> JoinHandle<Vec<bool>> {
let (f, t) = ( let (f, t) = (
(thread_id * ips_per_thread), (thread_id * ips_per_thread),
@ -56,7 +58,7 @@ fn create_scan_workers(
to: u32, to: u32,
target_port: u16, target_port: u16,
num_threads: u32, num_threads: u32,
ignorelist: Option<Vec<u32>> ignorelist: Option<Vec<u32>>,
) -> Vec<JoinHandle<Vec<bool>>> { ) -> Vec<JoinHandle<Vec<bool>>> {
println!("Starting wwmap..."); println!("Starting wwmap...");
@ -77,7 +79,12 @@ fn create_scan_workers(
// Clean up the rest // Clean up the rest
if ips_left > 0 { if ips_left > 0 {
let id_ignorelist = ignorelist.clone().unwrap_or_default(); 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 threads
@ -88,7 +95,7 @@ pub fn start_scan(
to: u32, to: u32,
target_port: u16, target_port: u16,
num_threads: u32, num_threads: u32,
ignorelist: Option<Vec<u32>> ignorelist: Option<Vec<u32>>,
) { ) {
let threads = create_scan_workers(from, to, target_port, num_threads, ignorelist); let threads = create_scan_workers(from, to, target_port, num_threads, ignorelist);

Loading…
Cancel
Save