mirror of https://github.com/E-Almqvist/wwmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
922 B
42 lines
922 B
2 years ago
|
use anyhow::{Result, anyhow};
|
||
|
use convert_base::Convert;
|
||
2 years ago
|
use crate::util;
|
||
2 years ago
|
|
||
2 years ago
|
/*
|
||
|
Algorithm: O(n)
|
||
2 years ago
|
|
||
2 years ago
|
let i = 0 .. u32:max_value()
|
||
2 years ago
|
|
||
2 years ago
|
# Convert each i to base 256 and we get all the ipv4 addresses
|
||
|
# This is waaaay better than a stupid loop
|
||
|
*/
|
||
|
|
||
2 years ago
|
#[derive(Debug)]
|
||
2 years ago
|
pub struct IPv4 {
|
||
2 years ago
|
pub id: u64,
|
||
|
pub ip: Vec<u16>
|
||
2 years ago
|
}
|
||
|
|
||
|
impl IPv4 {
|
||
2 years ago
|
pub fn new(id: u64) -> Self {
|
||
2 years ago
|
let mut base = Convert::new(10, 256);
|
||
2 years ago
|
|
||
|
let id_vec = util::number_to_vec(id); // push all digits into a vec
|
||
2 years ago
|
let ip = base.convert::<u8, u16>(&id_vec);
|
||
2 years ago
|
|
||
|
Self { id, ip }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
2 years ago
|
pub fn get_all(blacklist: Option<Vec<[u8; 4]>>) -> Result<Vec<[u8; 4]>> {
|
||
2 years ago
|
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)
|
||
|
// }
|
||
2 years ago
|
}
|