#ip地址 #子网 #检查 #接口

ip-in-subnet

检查子网是否包含IP地址

5个版本

0.1.4 2020年2月14日
0.1.3 2020年2月13日
0.1.2 2020年2月13日
0.1.1 2020年2月11日
0.1.0 2020年2月11日

11#子网 中排名

Download history 436/week @ 2024-03-13 463/week @ 2024-03-20 319/week @ 2024-03-27 196/week @ 2024-04-03 245/week @ 2024-04-10 401/week @ 2024-04-17 418/week @ 2024-04-24 306/week @ 2024-05-01 254/week @ 2024-05-08 283/week @ 2024-05-15 308/week @ 2024-05-22 186/week @ 2024-05-29 164/week @ 2024-06-05 356/week @ 2024-06-12 342/week @ 2024-06-19 250/week @ 2024-06-26

每月下载量 1,136

MIT 许可证

14KB
145

ip-in-subnet

检查子网是否包含IP地址。

用法

要使用ip-in-subnet,首先将以下内容添加到您的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);

依赖项

~71KB