pub fn local_ip_get() -> Option<IpAddr> {
    info!("local_ip_get for unix{}", "");
    let output = Command::new("ifconfig")
        .output()
        .expect("failed to execute `ifconfig`");

    let stdout = String::from_utf8(output.stdout).unwrap();

    let re = Regex::new(r#"(?m)^.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*$"#).unwrap();
    for cap in re.captures_iter(&stdout) {
        let host = cap.get(2).map_or("", |m| m.as_str());
        if host != "127.0.0.1" {
            if let Ok(addr) = host.parse::<Ipv4Addr>() {
                return Some(IpAddr::V4(addr));
            }
            if let Ok(addr) = host.parse::<Ipv6Addr>() {
                return Some(IpAddr::V6(addr));
            }
        }
    }
    return None;
}
///get local ip for unix with ifconfig
get local ip for unix with ifconfig
get local ip for unix with ifconfig
pub fn local_ip_get() -> Option<IpAddr> {
    info!("local_ip_get for unix{}", "");
    let output = Command::new("ifconfig")
        .output()
        .expect("failed to execute `ifconfig`");
    let stdout = String::from_utf8(output.stdout).unwrap();
    let re = Regex::new(r#"(?m)^.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*$"#).unwrap();
    for cap in re.captures_iter(&stdout) {
        let host = cap.get(2).map_or("", |m| m.as_str());
        if host != "127.0.0.1" {
            if let Ok(addr) = host.parse::<Ipv4Addr>() {
                return Some(IpAddr::V4(addr));
            }
            if let Ok(addr) = host.parse::<Ipv6Addr>() {
                return Some(IpAddr::V6(addr));
            }
        }
    }
    return None;
}
pub fn local_ip_get ( ) -> Option < IpAddr > { info ! ( " " " " ) ; let output = Command :: new ( " " ) . output ( ) . expect ( " " ) ; let stdout = String :: from_utf8 ( output . stdout ) . unwrap ( ) ; let re = Regex :: new ( r#"(?m)^.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*$"# ) . unwrap ( ) ; for cap in re . captures_iter ( & stdout ) { let host = cap . get ( 2 ) . map_or ( " " , | m | m . as_str ( ) ) ; if host != " " { if let Ok ( addr ) = host . parse :: < Ipv4Addr > ( ) { return Some ( IpAddr :: V4 ( addr ) ) ; } if let Ok ( addr ) = host . parse :: < Ipv6Addr > ( ) { return Some ( IpAddr :: V6 ( addr ) ) ; } } } return None ; }
get local ip for unix with ifconfig
get local ip for unix with ifconfig