feat: add __network/ipnet-demo
This commit is contained in:
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