use anyhow::{Result, anyhow}; use convert_base::Convert; use crate::util; /* Algorithm: O(n) 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 */ #[derive(Debug)] pub struct IPv4 { pub id: u64, pub ip: Vec } impl IPv4 { pub fn new(id: u64) -> Self { let mut base = Convert::new(10, 256); let id_vec = util::number_to_vec(id); // push all digits into a vec let ip = base.convert::(&id_vec); Self { id, ip } } } 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 //if combos.len() <= 0 { Err(anyhow!("Unable to generate IPv4 permutations")) // } else { // Ok(combos) // } }