3 个不稳定版本

0.4.1 2020 年 3 月 26 日
0.4.0 2020 年 3 月 26 日
0.3.0 2020 年 1 月 19 日

#2#httpbin

AGPL-3.0 或更高版本

16KB
122

mip

在 Rust 中获取 IPv4 地址 - 无依赖项!

crate mip 通过请求 http://httpbin.org/ip 并解析返回的输出获取本地 IP 地址。

它没有依赖项,仅依赖于 Rust std lib。

用法

将以下内容添加到 Cargo.toml

[dependencies]
mip = "0.4.0
use mip::IP;

fn main() {
    println!("My IP is {}", IP::is());
}

或无需 use


fn main() {
    println!("My IP is {}", mip::IP::is());
}

自定义端点

可以使用自定义端点代替使用 httpbin.org。自定义端点可能无法正确解析,因此在生产环境中使用之前请进行测试!

use mip::{IP, Endpoint};

fn main() {
    let ip = IP::with_endpoint(Endpoint {
        path: Some("/"),
        host: "checkip.dyndns.com",
        port: 80,
    });
    println!("{}", ip)
}

待办事项

需要完成的一些事情

许可证

见 LICENSE 文件。

无运行时依赖