#ip-address #subnet #net #iterator

subnetwork

Return all ip addresses of a subnetwork

39 releases

0.4.7 Nov 8, 2024
0.4.4 Aug 2, 2024
0.4.3 Jun 4, 2024
0.4.1 Dec 15, 2023
0.3.3 Jul 22, 2023

#1274 in Network programming

Download history 89/week @ 2024-07-27 51/week @ 2024-08-03 23/week @ 2024-08-10 3/week @ 2024-08-17 7/week @ 2024-08-24 8/week @ 2024-08-31 30/week @ 2024-09-07 55/week @ 2024-09-14 83/week @ 2024-09-21 119/week @ 2024-09-28 59/week @ 2024-10-05 24/week @ 2024-10-12 55/week @ 2024-10-19 129/week @ 2024-10-26 248/week @ 2024-11-02 73/week @ 2024-11-09

515 downloads per month
Used in pistol

MIT license

32KB
725 lines

subnetwork

Returns an iterator that iterates over all subnet IPs.

Rust

Example 1

use std::net::Ipv4Addr;
use subnetwork::Ipv4Pool;

fn main() {
    let ipv4_pool = Ipv4Pool::from("192.168.1.0/24").unwrap();
    for i in ipv4_pool {
        println!("{:?}", i);
    }
    let ipv4 = Ipv4Addr::new(192, 168, 1, 1);
    let ret = ipv4_pool.contain(ipv4);
    assert_eq!(ret, true);
}

Example 2

use std::net::Ipv4Addr;
use subnetwork::CrossIpv4Pool;

fn main() {
    let start = Ipv4Addr::new(192, 168, 1, 1);
    let end = Ipv4Addr::new(192, 168, 3, 254);
    let ips = CrossIpv4Pool::new(start, end).unwrap();
    for i in ips {
        println!("{:?}", i);
    }
}

Benchmark

You can see how our performance compares to other similar libraries here.


lib.rs:

The subnetwork crate provides a set of APIs to work with IP CIDRs in Rust.

Dependencies

~255–710KB
~16K SLoC