Struct IPTargets

Source
pub struct IPTargets(/* private fields */);
Expand description

Represents a list of IP targets

This wrapper is used to cut down on the memory needed to store entire network IP ranges. Rather than storing all 65536 IPs in a /16 CIDR block, or a range of IPS, this wrapper allows the storage of just CIDR or range in string form and then dynamically loops the IPs in that block when needed.

§Panics

Panics if an item in the list is not a valid IP

§Examples

let print_ip = |ip: net::Ipv4Addr| -> Result<(), ScanError> {
  println!("ip: {}", ip);
  Ok(())
};
let ips = IPTargets::new(
    vec![
      "192.168.0.1".to_string(),
      "172.17.0.1-172.17.0.24".to_string(),
      "192.168.68.1/24".to_string(),
    ]
);
ips.lazy_loop(print_ip).unwrap();

Implementations§

Source§

impl IPTargets

Source

pub fn new(list: Vec<String>) -> Arc<Self>

Returns a new instance of IPTargets using the provided list

Source

pub fn len(&self) -> usize

Returns the true length of the target list. If the underlying Vec<String> is just ["192.168.0.1/24"], then a call to “len” will return 256

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty

Source

pub fn lazy_loop<F: FnMut(Ipv4Addr) -> Result<(), ScanError>>( &self, cb: F, ) -> Result<(), ScanError>

loops over all targets including those that are not explicitly in the list but fall within a range or CIDR block defined in the list

Trait Implementations§

Source§

impl Debug for IPTargets

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.