From ac2352de10d13ec56ba92a66ebc504a9c3f31b8b Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 8 Aug 2022 15:13:52 +0200 Subject: [PATCH] Refactor --- src/{permutations.rs => ipv4.rs} | 3 +-- src/main.rs | 6 ++++-- src/scanner.rs | 4 ++-- src/util.rs | 2 -- 4 files changed, 7 insertions(+), 8 deletions(-) rename src/{permutations.rs => ipv4.rs} (87%) diff --git a/src/permutations.rs b/src/ipv4.rs similarity index 87% rename from src/permutations.rs rename to src/ipv4.rs index d980f16..a6dc6bc 100644 --- a/src/permutations.rs +++ b/src/ipv4.rs @@ -22,7 +22,6 @@ impl IPv4 { let mut base = Convert::new(10, 256); let id_vec = util::number_to_vec(id); // push all digits into a vec - println!("########## {:?}", id_vec); let ip = base.convert::(&id_vec); Self { id, ip } @@ -30,7 +29,7 @@ impl IPv4 { } -pub fn ipv4(blacklist: Option>) -> Result> { +pub fn get_all(blacklist: Option>) -> Result> { let blacklist = blacklist.unwrap_or(Vec::new()); let ips: Vec = (0..u32::max_value()).collect(); // 32 bit max value is the last IP diff --git a/src/main.rs b/src/main.rs index c2d1b68..e7c0f98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,14 @@ mod util; mod scanner; -mod permutations; +mod ipv4; + +use ipv4::IPv4; fn main() { // scanner::start_scan(100); // permutations::ipv4(None); - let ip = permutations::IPv4::new(256); + let ip = IPv4::new(256); println!("{:?}", ip); } diff --git a/src/scanner.rs b/src/scanner.rs index 575f8df..94d4574 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,7 +1,7 @@ use std::{net::{TcpStream, SocketAddr}, thread::JoinHandle}; use log::info; use std::thread; -use crate::permutations; +use crate::ipv4; async fn check_ack(dest: &SocketAddr) -> bool { if let Ok(res) = TcpStream::connect(dest) { @@ -12,7 +12,7 @@ async fn check_ack(dest: &SocketAddr) -> bool { } pub fn start_scan(depth: u32) { - let ip_list = permutations::ipv4(None); + let ip_list = ipv4::get_all(None); let mut threads: Vec> = Vec::new(); diff --git a/src/util.rs b/src/util.rs index 71cc93b..8d853e7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -33,11 +33,9 @@ pub fn number_to_vec(num: u64) -> Vec { let mut out: Vec = Vec::new(); let len = numlen(num); - println!("len={len}"); for idx in 0..len { let digit = digit(num, idx as u32); - println!("\t{:?}", digit); out.push(digit); }