27 lines
714 B
Rust
27 lines
714 B
Rust
|
pub fn find_local_address() -> Vec<std::net::IpAddr> {
|
||
|
use if_addrs::*;
|
||
|
|
||
|
let mut addresses = Vec::new();
|
||
|
|
||
|
if let Some(interfaces) = get_if_addrs().ok() {
|
||
|
for interface in interfaces {
|
||
|
match interface.addr {
|
||
|
IfAddr::V4(v4) => {
|
||
|
let ip = v4.ip;
|
||
|
let octets = ip.octets();
|
||
|
|
||
|
if octets[0] == 192 && octets[1] == 168 {
|
||
|
addresses.push(std::net::IpAddr::V4(ip));
|
||
|
}
|
||
|
}
|
||
|
IfAddr::V6(_v6) => {
|
||
|
// TODO
|
||
|
// addresses.push(IpAddr::V6(v6.ip));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addresses
|
||
|
}
|