aboutsummaryrefslogtreecommitdiff
path: root/src/utils/pub_ip.rs
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/pub_ip.rs
parent6c0dfddead48e603826fbf637fe51f02e8320223 (diff)
showing current public ip address (#43)
Diffstat (limited to 'src/utils/pub_ip.rs')
-rw-r--r--src/utils/pub_ip.rs15
1 files changed, 15 insertions, 0 deletions
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)
+}