aboutsummaryrefslogtreecommitdiff
path: root/src/utils/pub_ip.rs
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2022-01-31 14:08:30 +0100
committerÖzgür Kesim <oec@codeblau.de>2022-01-31 14:08:30 +0100
commitaf71cc35793c6757c19c619226a62f46e3288a57 (patch)
treeb1129593df8b3c68013fa29ef2d5ee7834c3ab5c /src/utils/pub_ip.rs
parent322b3c0624028d059613b557a6298001939e4ae9 (diff)
optional ipv6 address
Diffstat (limited to 'src/utils/pub_ip.rs')
-rw-r--r--src/utils/pub_ip.rs24
1 files changed, 18 insertions, 6 deletions
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)
}