feat: add __network/ipnet-demo
This commit is contained in:
16
__network/ipnet-demo/Cargo.lock
generated
Normal file
16
__network/ipnet-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
|
||||
|
||||
[[package]]
|
||||
name = "ipnet-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ipnet",
|
||||
]
|
||||
9
__network/ipnet-demo/Cargo.toml
Normal file
9
__network/ipnet-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "ipnet-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ipnet = "2.7.1"
|
||||
16
__network/ipnet-demo/src/main.rs
Normal file
16
__network/ipnet-demo/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
use ipnet::{Ipv4Net, Ipv6Net};
|
||||
|
||||
fn main() {
|
||||
let net4 = Ipv4Net::from_str("10.1.1.0/24").unwrap();
|
||||
let net6 = Ipv6Net::from_str("fd00::/24").unwrap();
|
||||
|
||||
println!("{:?}", net4);
|
||||
println!("{:?}", net6);
|
||||
|
||||
let ip: Ipv4Addr = "192.168.0.1".parse().unwrap();
|
||||
println!("{}", net4.contains(&ip));
|
||||
let ip: Ipv4Addr = "10.1.1.1".parse().unwrap();
|
||||
println!("{}", net4.contains(&ip));
|
||||
}
|
||||
Reference in New Issue
Block a user