aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorMustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com>2021-02-02 02:23:37 +0300
committerGitHub <noreply@github.com>2021-02-02 02:23:37 +0300
commit303808ea191f4c8d047c14a77a1bd322d4dcc081 (patch)
tree7496e0b92c754eafe734d6e10a9300c3d4fc00bb /src/utils
parent6c0dfddead48e603826fbf637fe51f02e8320223 (diff)
showing current public ip address (#43)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mod.rs1
-rw-r--r--src/utils/pub_ip.rs15
2 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 3b4eb7b..e70cf88 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -5,6 +5,7 @@ pub mod load_average;
pub mod memory;
pub mod mpd;
pub mod netspeed;
+pub mod pub_ip;
pub mod spotify;
pub mod time;
pub mod uptime;
diff --git a/src/utils/pub_ip.rs b/src/utils/pub_ip.rs
new file mode 100644
index 0000000..ce2da92
--- /dev/null
+++ b/src/utils/pub_ip.rs
@@ -0,0 +1,15 @@
+use crate::config::CONFIG;
+
+pub fn get_pub_ip() -> String {
+ let url = format!("http://api.ipify.org");
+ let err_string = String::from("Error");
+ let res = match minreq::get(url).send() {
+ Ok(resp) => match resp.as_str() {
+ Ok(res_str) => res_str.trim().to_string(),
+ Err(_) => err_string,
+ },
+ Err(_) => err_string,
+ };
+
+ format!(" {} {} {}", CONFIG.pub_ip.icon, res, CONFIG.seperator)
+}