From 5186bded0426225af336afef87427e62fc148996 Mon Sep 17 00:00:00 2001 From: Neshura Date: Wed, 15 Mar 2023 21:36:52 +0100 Subject: [PATCH] Closes #16 --- src/main.rs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3b7c6af..1be5b33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -272,8 +272,13 @@ impl Ips { match get(ipv4uri) { Ok(data) => { - self.ipv4 = data.text().expect("0.0.0.0").trim_end().to_owned(); - ret = true; + if data.status() == 200 { + self.ipv4 = data.text().expect("0.0.0.0").trim_end().to_owned(); + ret = true; + } + else { + ret = false; + } }, Err(_e) => { println!("Could not fetch IPv4"); @@ -285,16 +290,21 @@ impl Ips { match get(ipv6uri) { Ok(data) => { - let ipv6 = match data.text() { - Ok(ip) => {ip}, - Err(_) => {panic!("Expected IP, found none")}, - }; - let stripped = match ipv6.trim_end().strip_suffix(ipv6_interface) { - Some(string) => string.to_string(), - None => ":".to_string(), - }; - self.ipv6base = stripped; - ret = true && ret; // Only set ret to true if previous ret is also true + if data.status() == 200 { + let ipv6 = match data.text() { + Ok(ip) => {ip}, + Err(_) => {panic!("Expected IP, found none")}, + }; + let stripped = match ipv6.trim_end().strip_suffix(ipv6_interface) { + Some(string) => string.to_string(), + None => ":".to_string(), + }; + self.ipv6base = stripped; + ret = true && ret; // Only set ret to true if previous ret is also true + } + else { + ret = false; + } } Err(_e) => { println!("Could not fetch IPv6");