|
|
|
@ -1,8 +1,8 @@ |
|
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; |
|
|
|
|
|
|
|
|
|
use anyhow::{Result, anyhow}; |
|
|
|
|
use convert_base::Convert; |
|
|
|
|
use crate::util; |
|
|
|
|
use anyhow::{anyhow, Result}; |
|
|
|
|
use convert_base::Convert; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
Algorithm: O(n) |
|
|
|
@ -17,7 +17,7 @@ let i = 0 .. u32:max_value() |
|
|
|
|
pub struct IPv4 { |
|
|
|
|
pub id: u64, |
|
|
|
|
pub ip: Vec<u8>, |
|
|
|
|
pub ignore: bool |
|
|
|
|
pub ignore: bool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl IPv4 { |
|
|
|
@ -37,7 +37,11 @@ impl IPv4 { |
|
|
|
|
// Reverse it so that we start from the top
|
|
|
|
|
ip = ip.into_iter().rev().collect(); |
|
|
|
|
|
|
|
|
|
Self { id, ip, ignore: false } |
|
|
|
|
Self { |
|
|
|
|
id, |
|
|
|
|
ip, |
|
|
|
|
ignore: false, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> { |
|
|
|
@ -61,15 +65,20 @@ pub fn get_all(ignorelist: Option<Vec<u64>>) -> Result<Vec<IPv4>> { |
|
|
|
|
// Get all of the "ids"
|
|
|
|
|
let ids: Vec<u32> = (0..u32::max_value()).collect(); |
|
|
|
|
|
|
|
|
|
let ips: Vec<IPv4> = ids.iter().map(|&ip| { |
|
|
|
|
let ips: Vec<IPv4> = ids |
|
|
|
|
.iter() |
|
|
|
|
.map(|&ip| { |
|
|
|
|
// Make IP
|
|
|
|
|
let mut ip = IPv4::new(ip as u64); |
|
|
|
|
|
|
|
|
|
// Make the IP "ignored" if it is in the ignorelist
|
|
|
|
|
if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { ip.ignore = true; } |
|
|
|
|
if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { |
|
|
|
|
ip.ignore = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ip |
|
|
|
|
}).collect(); |
|
|
|
|
}) |
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
Ok(ips) |
|
|
|
|
} |
|
|
|
|