diff --git a/Cargo.toml b/Cargo.toml index d345af8..ffc4a96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ edition = "2021" # packet = "0.1.4" anyhow = "1" log = "0.4" -permutator = "0.4.3" +convert-base = "1.1.2" diff --git a/src/main.rs b/src/main.rs index 16941b0..e27a4bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,5 +8,6 @@ mod scanner; mod permutations; fn main() { - scanner::start_scan(100); + // scanner::start_scan(100); + permutations::ipv4(None); } diff --git a/src/permutations.rs b/src/permutations.rs index 7080fe7..dfa5b4b 100644 --- a/src/permutations.rs +++ b/src/permutations.rs @@ -1,11 +1,48 @@ -use permutator::Permutation; +use anyhow::{Result, anyhow}; +use convert_base::Convert; -pub fn get_ipv4_permutations(start_pos: [u8; 4]) -> Vec> { - let perms: Vec> = Vec::new(); +/* +Algorithm: O(n) - // (2^8)^4 = 2^32 => 32bit - let range: Box<[u8; u32::max_value() as usize]> = (0..u8::max_value()).collect::>().try_into().expect("nope"); +let i = 0 .. u32:max_value() +# Convert each i to base 256 and we get all the ipv4 addresses +# This is waaaay better than a stupid loop - perms + +*/ + +// TODO: make a better implementation of this function +fn digits(n: usize) -> impl Iterator { + n.to_string() + .chars() + .map(|digit| digit.to_digit(10).unwrap()) + .collect::>() + .into_iter() +} + +struct IPv4 { + id: u32, + ip: Vec +} + +impl IPv4 { + fn new(self: &mut Self, id: u32) -> Self { + let mut base = Convert::new(10, 256); + let ip = base.convert::(&id); + + Self { id, ip } + } +} + + +pub fn ipv4(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 + + //if combos.len() <= 0 { + Err(anyhow!("Unable to generate IPv4 permutations")) +// } else { +// Ok(combos) +// } } diff --git a/src/scanner.rs b/src/scanner.rs index 21d8784..575f8df 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -12,6 +12,8 @@ async fn check_ack(dest: &SocketAddr) -> bool { } pub fn start_scan(depth: u32) { + let ip_list = permutations::ipv4(None); + let mut threads: Vec> = Vec::new(); for i in 0..depth {