Crate iprange

source ·
Expand description

iprange is a library for managing IP ranges.

An IpRange is a set of networks. The type of the networks it holds is specified by the generics type of IpRange.

You can add or remove an IpNet from an IpRange. An IpNet can be either an Ipv4Net or an Ipv6Net.

It also supports these useful operations:

Here is a simple example:

extern crate iprange;
extern crate ipnet;

use std::net::Ipv4Addr;
use iprange::IpRange;
use ipnet::Ipv4Net;

fn main() {
    let ip_range: IpRange<Ipv4Net> = ["10.0.0.0/8", "172.16.0.0/16", "192.168.1.0/24"]
        .iter()
        .map(|s| s.parse().unwrap())
        .collect();

    assert!(ip_range.contains(&"172.16.32.1".parse::<Ipv4Addr>().unwrap()));
    assert!(ip_range.contains(&"192.168.1.1".parse::<Ipv4Addr>().unwrap()));
}

Structs

A set of networks that supports various operations:
An iterator over the networks in an IpRange.
Node of the inner radix trie.

Traits

An abstraction for IP networks.
Anything that can be converted to IpNet.
Used for internal traversing.