Skip to content

Instantly share code, notes, and snippets.

@kstep
Created October 10, 2014 11:05
Show Gist options
  • Save kstep/9036e9eb002a4fbbfcbf to your computer and use it in GitHub Desktop.
Save kstep/9036e9eb002a4fbbfcbf to your computer and use it in GitHub Desktop.
use std::io::net;
fn get_my_external_ip() -> Option<net::ip::IpAddr> {
net::tcp::TcpStream::connect("8.8.8.8", 53).and_then(|ref mut s| s.socket_name()).map(|a| a.ip).ok()
}
fn main() {
println!("My external IP: {}", get_my_external_ip());
}
@kstep
Copy link
Author

kstep commented Oct 10, 2014

$ rustc ./extip.rs
$ ./extip
My external IP: 192.168.1.200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment