Crates.io | my_internet_ip |
lib.rs | my_internet_ip |
version | 0.1.1 |
source | src |
created_at | 2018-03-01 22:02:07.998728 |
updated_at | 2018-10-03 09:18:02.519773 |
description | Retrieve the public IP of the machine your app runs on. |
homepage | https://gitlab.com/philippludwig/my-internet-ip |
repository | https://gitlab.com/philippludwig/my-internet-ip.git |
max_upload_size | |
id | 53366 |
size | 6,093 |
"My Internet IP" is a small rust crate for retrieving the public IP of the device this code is executed on.
The code contains no more unwrap
, but the return type of get
has been changed to the new enum MyIpError
which wraps all
errors which may occur during retrieving of the IP.
extern crate my_internet_ip;
fn main() {
let ip: ::std::net::IpAddr = match my_internet_ip::get() {
Ok(ip) => ip,
Err(e) => panic!("Could not get IP: {}", e)
};
// Do something with the IP, e.g. print it
}
Note: The call to my_internet_ip::get()
blocks until the public IP
was retrieved or an error occurred.
my_internet_ip = "0.1.1"
This crate uses the curl crate to access http://www.myip.ch and parse the result.
MIT