From 5f30f64434b86f8ba6b6a61d50d66455069596be Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sun, 14 Aug 2022 17:44:12 +0200 Subject: [PATCH] CIDR for IPv4Ranges --- src/cli.rs | 9 +++++++++ src/ipv4.rs | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index a54b57f..c6da913 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -42,4 +42,13 @@ pub struct Args { required = false )] 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, } diff --git a/src/ipv4.rs b/src/ipv4.rs index 128c181..26abc73 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -1,5 +1,6 @@ use crate::util; use anyhow::{anyhow, Result}; +use cidr_utils::cidr::Ipv4Cidr; use convert_base::Convert; use std::convert::TryInto; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; @@ -76,6 +77,13 @@ impl IPv4Range { id_ignore, } } + + pub fn from_cidr(cidr_string: String, id_ignore: Vec) -> 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 {