Crates.io | ip-in-subnet |
lib.rs | ip-in-subnet |
version | 0.1.4 |
source | src |
created_at | 2020-02-11 19:11:22.113418 |
updated_at | 2020-02-14 01:40:50.355172 |
description | Checking that subnet contains an IP address |
homepage | |
repository | |
max_upload_size | |
id | 207418 |
size | 13,078 |
Checking that subnet contains an IP address.
To use ip-in-subnet
, first add this to your Cargo.toml
:
[dependencies]
ip-in-subnet = "0.1"
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);
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);
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);
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);