diff --git a/README.md b/README.md index 087d7e5..a7dadc9 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ Project or files: │   ├── async-speed-limit │   ├── dingo │   ├── ip +│   ├── ipnet-demo │   ├── iptables │   ├── mailsend │   ├── message_io @@ -269,6 +270,6 @@ Project or files: ├── vec.rs └── while.rs -238 directories, 39 files +239 directories, 39 files ``` diff --git a/__network/ipnet-demo/Cargo.lock b/__network/ipnet-demo/Cargo.lock new file mode 100644 index 0000000..d2cbd13 --- /dev/null +++ b/__network/ipnet-demo/Cargo.lock @@ -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", +] diff --git a/__network/ipnet-demo/Cargo.toml b/__network/ipnet-demo/Cargo.toml new file mode 100644 index 0000000..70aa10f --- /dev/null +++ b/__network/ipnet-demo/Cargo.toml @@ -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" diff --git a/__network/ipnet-demo/src/main.rs b/__network/ipnet-demo/src/main.rs new file mode 100644 index 0000000..f335c98 --- /dev/null +++ b/__network/ipnet-demo/src/main.rs @@ -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)); +}