optional ipv6 address

This commit is contained in:
Özgür Kesim 2022-01-31 14:08:30 +01:00
parent 322b3c0624
commit af71cc3579
2 changed files with 20 additions and 6 deletions

View File

@ -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,
}
}

View File

@ -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)
}