8 个版本 (3 个稳定版)
1.0.2 | 2022 年 9 月 27 日 |
---|---|
1.0.1 | 2021 年 3 月 7 日 |
0.0.5 | 2021 年 3 月 7 日 |
0.0.4 | 2016 年 10 月 1 日 |
0.0.2 | 2016 年 9 月 30 日 |
#1948 在 网络编程
每月 229 次下载
在 2 crates 中使用
11KB
144 行
Rust IPGen 库
在 Rust 中实现 IPGen 规范 的官方版本
IPGen 是一个在 Rust 中生成唯一且可重现 IP 地址的库。此库生成的 IP 地址高度唯一(取决于您的子网前缀),但如果您传入相同的输入,它将生成相同的 IP 地址。您还可以使用我们的 命令行工具 生成 IP 地址。
入门指南
将 ipgen
添加到您的 Cargo.toml
文件中的依赖项。
[dependencies]
ipgen = "1"
在您的程序中使用它如下所示:
fn main() -> ipgen::Result<()> {
// Compute subnet ID
let subnet = ipgen::subnet("App 1")?;
assert_eq!(subnet, "ba3d");
// Or compute an IPv6 address
// Note you can also pass in an IPv4 network to generate an IPv4
let network = "fd52:f6b0:3162::/48".parse()?;
let ip = ipgen::ip("App 1", network)?;
assert_eq!(ip.to_string(), "fd52:f6b0:3162:46a1:2a4f:89e8:8aed:1327");
Ok(())
}
依赖项
~475KB
~11K SLoC