diff --git a/Cargo.toml b/Cargo.toml index 2cc4d54..4479bf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ name = "breedenter-rust" version = "0.1.5" edition = "2021" -authors = ["wwng "] +authors = ["wwng "] description = "A rust version of breedenter." [dependencies] -open = "3.2.0" +open = "3.2.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2ceed0c..4cc4590 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,26 @@ use std::io::Read; use std::net::UdpSocket; use std::thread; use std::time::Duration; + +fn localip_get() -> Option { + let socket = match UdpSocket::bind("0.0.0.0:0") { + Ok(s) => s, + Err(_) => return None, + }; + + match socket.connect("192.168.1.1:80") { + Ok(()) => (), + Err(_) => return None, + }; + + match socket.local_addr() { + Ok(addr) => return Some(addr.ip().to_string()), + Err(_) => return None, + }; +} + fn main() -> std::io::Result<()> { + println!("Local IP: {}", localip_get().unwrap()); let socket = UdpSocket::bind("0.0.0.0:37540")?; socket.set_broadcast(true)?; socket.set_nonblocking(true).unwrap();