5 releases

0.1.4 Feb 14, 2020
0.1.3 Feb 13, 2020
0.1.2 Feb 13, 2020
0.1.1 Feb 11, 2020
0.1.0 Feb 11, 2020

#14 in #subnet

Download history 318/week @ 2024-07-20 173/week @ 2024-07-27 195/week @ 2024-08-03 200/week @ 2024-08-10 244/week @ 2024-08-17 336/week @ 2024-08-24 568/week @ 2024-08-31 369/week @ 2024-09-07 516/week @ 2024-09-14 797/week @ 2024-09-21 503/week @ 2024-09-28 537/week @ 2024-10-05 446/week @ 2024-10-12 497/week @ 2024-10-19 322/week @ 2024-10-26 649/week @ 2024-11-02

1,962 downloads per month

MIT license

14KB
145 lines

ip-in-subnet

Checking that subnet contains an IP address.

Usage

To use ip-in-subnet, first add this to your Cargo.toml:

[dependencies]
ip-in-subnet = "0.1"

Examples

Check that subnet contains an interface.

extern crate ip_in_subnet;

use ip_in_subnet::iface_in_subnet;

let res = iface_in_subnet("192.168.182.1", "192.168.182.0/24").unwrap();
assert!(res);
extern crate ip_in_subnet;

use ip_in_subnet::iface_in_subnet;

let res = iface_in_subnet("192.168.183.1", "192.168.182.0/24").unwrap();
assert!(!res);

Check that any subnet contains an interface.

extern crate ip_in_subnet;

use ip_in_subnet::iface_in_any_subnet;

let subnets = vec!["192.168.181.0/24", "192.168.182.0/24"];
let res = iface_in_any_subnet("192.168.182.1", &subnets).unwrap();
assert!(res);
extern crate ip_in_subnet;

use ip_in_subnet::iface_in_any_subnet;

let subnets = vec!["192.168.181.0/24", "192.168.182.0/24"];
let res = iface_in_any_subnet("192.168.183.1", &subnets).unwrap();
assert!(!res);

Check that all subnets contains an interface.

extern crate ip_in_subnet;

use ip_in_subnet::iface_in_all_subnets;

let subnets = vec!["192.168.182.0/24", "192.168.182.1/32"];
let res = iface_in_all_subnets("192.168.182.1", &subnets).unwrap();
assert!(res);
extern crate ip_in_subnet;

use ip_in_subnet::iface_in_all_subnets;

let subnets = vec!["192.168.182.0/24", "192.168.182.2/32"];
let res = iface_in_all_subnets("192.168.182.1", &subnets).unwrap();
assert!(!res);

Check that any subnet contains any interface.

extern crate ip_in_subnet;

use ip_in_subnet::any_iface_in_any_subnet;

let ifaces = vec!["192.168.182.1", "192.168.182.2"];
let subnets = vec!["192.168.181.0/24", "192.168.182.2/32"];
let res = any_iface_in_any_subnet(&ifaces, &subnets).unwrap();
assert!(res);
extern crate ip_in_subnet;

use ip_in_subnet::any_iface_in_any_subnet;

let ifaces = vec!["192.168.182.1", "192.168.182.2"];
let subnets = vec!["192.168.181.0/24", "192.168.182.3/32"];
let res = any_iface_in_any_subnet(&ifaces, &subnets).unwrap();
assert!(!res);

Dependencies

~71KB