Crates.io | subnet-utils |
lib.rs | subnet-utils |
version | |
source | src |
created_at | 2024-12-02 20:00:56.438426 |
updated_at | 2024-12-02 20:00:56.438426 |
description | A Rust subnet utility library |
homepage | https://github.com/s0ssh/subnet-utils-rs |
repository | https://github.com/s0ssh/subnet-utils-rs |
max_upload_size | |
id | 1469148 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Simple IP subnet utilities
To use subnet-utils
, first add this to your Cargo.toml
:
[dependencies]
subnet-utils = "0.1"
Check if subnet contains an address.
use std::net::{IpAddr, Ipv4Addr};
use subnet_utils::addr_in_subnet;
let res = addr_in_subnet(&IpAddr::V4(Ipv4Addr::new(192, 168, 182, 1)), "192.168.182.0/24").unwrap();
assert!(res);
Check if any subnet contains an address.
use std::net::{IpAddr, Ipv4Addr};
use subnet_utils::addr_in_any_subnet;
let subnets = vec!["192.168.181.0/24", "192.168.182.0/24"];
let res = addr_in_any_subnet(&IpAddr::V4(Ipv4Addr::new(192, 168, 182, 1)), &subnets).unwrap();
assert!(res);
Check if all subnets contain an address.
use std::net::{IpAddr, Ipv4Addr};
use subnet_utils::addr_in_all_subnets;
let subnets = vec!["192.168.182.0/24", "192.168.182.1/32"];
let res = addr_in_all_subnets(&IpAddr::V4(Ipv4Addr::new(192, 168, 182, 1)), &subnets).unwrap();
assert!(res);
Check if any subnet contains any address.
use std::net::{IpAddr, Ipv4Addr};
use subnet_utils::any_addr_in_any_subnet;
let addrs = vec![IpAddr::V4(Ipv4Addr::new(192, 168, 182, 1)), IpAddr::V4(Ipv4Addr::new(192, 168, 182, 2))];
let subnets = vec!["192.168.181.0/24", "192.168.182.2/32"];
let res = any_addr_in_any_subnet(&addrs, &subnets).unwrap();
assert!(res);
Copyright © 2024 s0s
This software is released under:
Please see the license file (LICENSE.md) for more information.