E. Almqvist 2 years ago
parent dc723a58e1
commit 98e56dd1b5
  1. 19
      src/scanner.rs

@ -1,4 +1,5 @@
use crate::ipv4; use crate::ipv4;
use anyhow::{Result, anyhow};
use log::info; use log::info;
use std::thread; use std::thread;
use std::{ use std::{
@ -6,7 +7,7 @@ use std::{
thread::JoinHandle, thread::JoinHandle,
}; };
async fn check_ack(dest: &SocketAddr) -> bool { async fn tcp_scan(dest: &SocketAddr) -> bool {
if let Ok(res) = TcpStream::connect(dest) { if let Ok(res) = TcpStream::connect(dest) {
info!("Got TCP ack from: {:?}", dest); info!("Got TCP ack from: {:?}", dest);
return true; return true;
@ -14,18 +15,26 @@ async fn check_ack(dest: &SocketAddr) -> bool {
false false
} }
pub fn start_scan(depth: u32) { pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Vec<u64>) -> Result<()> {
let ip_list = ipv4::get_all(None); let ip_list = ipv4::get_all(None)?;
// casting hell
// Get the amount of needed threads
let needed_threads = ((ip_list.len() as f32) / num_threads as f32).ceil() as u32;
// Container for all of our threads
let mut threads: Vec<JoinHandle<()>> = Vec::new(); let mut threads: Vec<JoinHandle<()>> = Vec::new();
for i in 0..depth { // Create all of our threads
for i in 0..needed_threads {
let thread = thread::spawn(|| { let thread = thread::spawn(|| {
println!("hi");
// do scan // do scan
let target = ip_list[i as usize].to_socketaddr(target_port)?;
}); });
threads.push(thread); threads.push(thread);
} }
Ok(())
} }
/* /*

Loading…
Cancel
Save