E. Almqvist 2 years ago
parent 292a257c59
commit 09bf94bcd2
  1. 4
      src/ipv4.rs
  2. 16
      src/main.rs
  3. 30
      src/scanner.rs

@ -29,7 +29,7 @@ impl IPv4 {
// In case we are missing some digits // In case we are missing some digits
if ip.len() < 4 { if ip.len() < 4 {
for i in 0..(4 - ip.len()) { for _ in 0..(4 - ip.len()) {
ip.insert(0, 0); ip.insert(0, 0);
} }
} }
@ -38,7 +38,7 @@ impl IPv4 {
ip = ip.into_iter().rev().collect(); ip = ip.into_iter().rev().collect();
// convert to array // convert to array
let ip: [u8; 4] = ip.try_into().unwrap_or_else(|v: Vec<u8>| panic!("Unable to convert Vec to [u8; 4] for IPv4!")); let ip: [u8; 4] = ip.try_into().unwrap_or_else(|_: Vec<u8>| panic!("Unable to convert Vec to [u8; 4] for IPv4!"));
Self { Self {
id, id,

@ -1,21 +1,9 @@
#![allow(
dead_code,
unused_variables,
//unused_imports, // TODO: rm
)]
mod ipv4; mod ipv4;
mod scanner; mod scanner;
mod util; mod util;
use ipv4::IPv4; //use ipv4::IPv4;
fn main() { fn main() {
// scanner::start_scan(100);
// permutations::ipv4(None);
let ip = IPv4::new((u32::max_value()) as u64);
println!("{:?}", ip);
let ip = IPv4::new(256);
println!("{:?}", ip);
} }

@ -5,33 +5,31 @@ use std::thread;
use std::thread::JoinHandle; use std::thread::JoinHandle;
use std::net::{SocketAddr, TcpStream}; use std::net::{SocketAddr, TcpStream};
fn tcp_scan(dest: &SocketAddr) -> bool { fn tcp_scan(mut target: ipv4::IPv4, target_port: u16) -> bool {
let dest = target.to_socketaddr(target_port).unwrap();
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, res);
return true; return true;
} }
false false
} }
// TODO: do thread optimization
pub fn scan(target: &ipv4::IPv4) -> bool {
true
}
fn create_scan_thread( 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
) -> JoinHandle<Vec<bool>> { ) -> JoinHandle<Vec<bool>> {
thread::spawn(move || { thread::spawn(move || {
info!("Starting thread worker #{}", thread_id);
let mut results: Vec<bool> = Vec::new(); let mut results: Vec<bool> = Vec::new();
// do the scan thing // do the scan thing
for i in 0..ips_per_thread { for i in 0..ips_per_thread {
let id = (thread_id * ips_per_thread) + i; let id = (thread_id * ips_per_thread) + i;
let ref target = ip_list[id as usize]; let ref target = ip_list[id as usize];
let result = scan(&target); let result = tcp_scan(*target, target_port);
results.push(result); results.push(result);
} }
@ -55,24 +53,14 @@ 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
)); ));
} }
// 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)); threads.push(create_scan_thread(ip_list, num_threads, ips_left, target_port));
} }
Ok(()) Ok(())
} }
/*
depth: u32
blacklist_ips: Vec
pre:
# generate IPs
ALL_IPS: Vec<Vecu8>> = ...
*/

Loading…
Cancel
Save