Permutations algo & other stuff

cli
E. Almqvist 2 years ago
parent 9a41171fc6
commit 4ed00b2039
  1. 2
      Cargo.toml
  2. 3
      src/main.rs
  3. 49
      src/permutations.rs
  4. 2
      src/scanner.rs

@ -9,4 +9,4 @@ edition = "2021"
# packet = "0.1.4" # packet = "0.1.4"
anyhow = "1" anyhow = "1"
log = "0.4" log = "0.4"
permutator = "0.4.3" convert-base = "1.1.2"

@ -8,5 +8,6 @@ mod scanner;
mod permutations; mod permutations;
fn main() { fn main() {
scanner::start_scan(100); // scanner::start_scan(100);
permutations::ipv4(None);
} }

@ -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<Vec<u8>> { /*
let perms: Vec<Vec<u8>> = Vec::new(); Algorithm: O(n)
// (2^8)^4 = 2^32 => 32bit let i = 0 .. u32:max_value()
let range: Box<[u8; u32::max_value() as usize]> = (0..u8::max_value()).collect::<Box<[u8]>>().try_into().expect("nope");
# 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<Item = u32> {
n.to_string()
.chars()
.map(|digit| digit.to_digit(10).unwrap())
.collect::<Vec<_>>()
.into_iter()
}
struct IPv4 {
id: u32,
ip: Vec<u8>
}
impl IPv4 {
fn new(self: &mut Self, id: u32) -> Self {
let mut base = Convert::new(10, 256);
let ip = base.convert::<u32, u8>(&id);
Self { id, ip }
}
}
pub fn ipv4(blacklist: Option<Vec<[u8; 4]>>) -> Result<Vec<[u8; 4]>> {
let blacklist = blacklist.unwrap_or(Vec::new());
let ips: Vec<u32> = (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)
// }
} }

@ -12,6 +12,8 @@ async fn check_ack(dest: &SocketAddr) -> bool {
} }
pub fn start_scan(depth: u32) { pub fn start_scan(depth: u32) {
let ip_list = permutations::ipv4(None);
let mut threads: Vec<JoinHandle<()>> = Vec::new(); let mut threads: Vec<JoinHandle<()>> = Vec::new();
for i in 0..depth { for i in 0..depth {

Loading…
Cancel
Save