diff --git a/src/config/pub_ip.rs b/src/config/pub_ip.rs index df27f28..f7539d0 100644 --- a/src/config/pub_ip.rs +++ b/src/config/pub_ip.rs @@ -5,6 +5,7 @@ use std::default::Default; pub struct PubIp { pub icon: String, pub enabled: bool, + pub show6: bool, pub delay: f64, } @@ -13,6 +14,7 @@ impl Default for PubIp { PubIp { icon: String::from(""), enabled: false, + show6: false, delay: 120.0, } } diff --git a/src/utils/pub_ip.rs b/src/utils/pub_ip.rs index dde354a..ada58be 100644 --- a/src/utils/pub_ip.rs +++ b/src/utils/pub_ip.rs @@ -2,16 +2,28 @@ use crate::config::CONFIG; use crate::types::ThreadsData; pub async fn get_pub_ip() -> ThreadsData { - let url = "http://api.ipify.org".to_string(); - let _err = String::from("Error"); - let res = match minreq::get(url).send() { + let url4 = "http://api.ipify.org".to_string(); + let url6 = "http://api64.ipify.org".to_string(); + let _err4 = String::from("Error4"); + let res4 = match minreq::get(url4).send() { Ok(resp) => match resp.as_str() { Ok(res_str) => res_str.trim().to_string(), - Err(_) => _err, + Err(_) => _err4, }, - Err(_) => _err, + Err(_) => _err4, }; + let _err6 = String::from("Error6"); + let mut res6 = String::from(""); + if CONFIG.pub_ip.show6 { + res6 = match minreq::get(url6).send() { + Ok(resp) => match resp.as_str() { + Ok(res_str) => format!("[{}]", res_str.trim().to_string()), + Err(_) => _err6, + }, + Err(_) => _err6, + } + } - let data = format!(" {} {} {}", CONFIG.pub_ip.icon, res, CONFIG.seperator); + let data = format!(" {} {} {} {}", CONFIG.pub_ip.icon, res4, res6, CONFIG.seperator); ThreadsData::PubIp(data) }