5 releases

Uses old Rust 2015

0.1.1 Oct 3, 2018
0.1.0 Oct 3, 2018
0.0.3 Mar 1, 2018
0.0.2 Mar 1, 2018
0.0.1 Mar 1, 2018

#9 in #retrieving

Download history 22/week @ 2024-03-11 23/week @ 2024-03-18 4/week @ 2024-03-25 31/week @ 2024-04-01 11/week @ 2024-04-08 17/week @ 2024-04-15 19/week @ 2024-04-22 14/week @ 2024-04-29 8/week @ 2024-05-06 20/week @ 2024-05-13 17/week @ 2024-05-20 13/week @ 2024-05-27 16/week @ 2024-06-03 8/week @ 2024-06-10 17/week @ 2024-06-17 13/week @ 2024-06-24

56 downloads per month
Used in wyr

MIT license

5KB

My Internet IP Rust Crate

"My Internet IP" is a small rust crate for retrieving the public IP of the device this code is executed on.

Changes in 0.1.1

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.

Example

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.

Cargo.toml

my_internet_ip = "0.1.1"

How it works

This crate uses the curl crate to access http://www.myip.ch and parse the result.

Ideas for contributions

  • Support async retrieval of the IP
  • Use other sites to retrieve the IP (maybe STUN server?) and select one randomly
  • Clear up the code (it is quite convoluted, but it works)

License

MIT

Dependencies

~7–15MB
~207K SLoC