3 unstable releases
0.4.1 | Mar 26, 2020 |
---|---|
0.4.0 | Mar 26, 2020 |
0.3.0 | Jan 19, 2020 |
#2 in #httpbin
16KB
122 lines
mip
Get IPv4 address in rust - with 0 dependencies!
Crate mip
gets the local IP address by requesting http://httpbin.org/ip
and parsing the returned output.
It has 0 dependencies and only relies on the Rust std lib.
Usage
Add the following to Cargo.toml
.
[dependencies]
mip = "0.4.0
use mip::IP;
fn main() {
println!("My IP is {}", IP::is());
}
Or without use
fn main() {
println!("My IP is {}", mip::IP::is());
}
Custom Endpoint
Instead of using httpbin.org a custom endpoint can be used. Custom endpoints may not parse properly so test before using in production!
use mip::{IP, Endpoint};
fn main() {
let ip = IP::with_endpoint(Endpoint {
path: Some("/"),
host: "checkip.dyndns.com",
port: 80,
});
println!("{}", ip)
}
Todo
Some things that need to be done
- Clean-up code
- Write proper docs
- Use multiple providers randomly / with fallback like http://checkip.dyndns.com and http://checkip.dyndns.org
- Support IPv6?
License
See LICENSE file.