CIDR for IPv4Ranges

main
E. Almqvist 2 years ago
parent 30a03a974c
commit 5f30f64434
  1. 9
      src/cli.rs
  2. 8
      src/ipv4.rs

@ -42,4 +42,13 @@ pub struct Args {
required = false required = false
)] )]
pub verbose: bool, pub verbose: bool,
#[clap(
help = "IPv4 subnet range (CIDR). Leave empty for the whole internet.",
short = 'r',
long = "range",
default_value = "0.0.0.0/0",
required = false
)]
pub cidr: String,
} }

@ -1,5 +1,6 @@
use crate::util; use crate::util;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use cidr_utils::cidr::Ipv4Cidr;
use convert_base::Convert; use convert_base::Convert;
use std::convert::TryInto; use std::convert::TryInto;
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::net::{IpAddr, Ipv4Addr, SocketAddr};
@ -76,6 +77,13 @@ impl IPv4Range {
id_ignore, id_ignore,
} }
} }
pub fn from_cidr(cidr_string: String, id_ignore: Vec<u32>) -> Self {
let cidr = Ipv4Cidr::from_str(cidr_string).unwrap();
let (from, to) = (cidr.first(), cidr.last());
Self::new(from, to, id_ignore)
}
} }
impl Iterator for IPv4Range { impl Iterator for IPv4Range {

Loading…
Cancel
Save