|
|
@ -1,9 +1,9 @@ |
|
|
|
use crate::ipv4; |
|
|
|
use crate::ipv4; |
|
|
|
use anyhow::Result; |
|
|
|
use anyhow::Result; |
|
|
|
use log::info; |
|
|
|
use log::info; |
|
|
|
|
|
|
|
use std::net::{SocketAddr, TcpStream}; |
|
|
|
use std::thread; |
|
|
|
use std::thread; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::net::{SocketAddr, TcpStream}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn tcp_scan(mut target: ipv4::IPv4, target_port: u16) -> bool { |
|
|
|
fn tcp_scan(mut target: ipv4::IPv4, target_port: u16) -> bool { |
|
|
|
let dest = target.to_socketaddr(target_port).unwrap(); |
|
|
|
let dest = target.to_socketaddr(target_port).unwrap(); |
|
|
@ -19,7 +19,7 @@ fn create_scan_thread( |
|
|
|
ip_list: Vec<ipv4::IPv4>, |
|
|
|
ip_list: Vec<ipv4::IPv4>, |
|
|
|
thread_id: u32, |
|
|
|
thread_id: u32, |
|
|
|
ips_per_thread: u32, |
|
|
|
ips_per_thread: u32, |
|
|
|
target_port: u16 |
|
|
|
target_port: u16, |
|
|
|
) -> JoinHandle<Vec<bool>> { |
|
|
|
) -> JoinHandle<Vec<bool>> { |
|
|
|
thread::spawn(move || { |
|
|
|
thread::spawn(move || { |
|
|
|
info!("Starting thread worker #{}", thread_id); |
|
|
|
info!("Starting thread worker #{}", thread_id); |
|
|
@ -53,13 +53,18 @@ pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Option<Vec<u64 |
|
|
|
ip_list.clone(), |
|
|
|
ip_list.clone(), |
|
|
|
thread_id, |
|
|
|
thread_id, |
|
|
|
ips_per_thread, |
|
|
|
ips_per_thread, |
|
|
|
target_port |
|
|
|
target_port, |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// create the last thread to do the job
|
|
|
|
// create the last thread to do the job
|
|
|
|
if ips_left > 0 { |
|
|
|
if ips_left > 0 { |
|
|
|
threads.push(create_scan_thread(ip_list, num_threads, ips_left, target_port)); |
|
|
|
threads.push(create_scan_thread( |
|
|
|
|
|
|
|
ip_list, |
|
|
|
|
|
|
|
num_threads, |
|
|
|
|
|
|
|
ips_left, |
|
|
|
|
|
|
|
target_port, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|