]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
http-client-functions.pl: Add FetchPublicIP function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 18 Apr 2025 10:54:41 +0000 (12:54 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:21:24 +0000 (14:21 +0000)
This functions uses the newly introduced downloader to fetch
the pulic IPv4 address on red and will replace the current used one
from the general-functions.pl library.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/http-client-functions.pl

index 26ead69082c6c94d2773e17f645ea36298ebf3d0..bfb9fdd201ed68ad75cfa58255073f642f05b1a0 100644 (file)
@@ -287,4 +287,24 @@ sub downloader (%) {
        }
 }
 
+#
+# Tiny function to grab the public red IPv4 address using LWL.
+#
+sub FetchPublicIp {
+       # URL to grab the public IP.
+       my $url = "https://checkip4.dns.lightningwirelabs.com";
+
+       # Call downloader to fetch the public IP.
+       my $response = &downloader("URL" => $url);
+
+       # Omit the address from the resonse message.
+       if ($response =~ /Your IP address is: (\d+.\d+.\d+.\d+)/) {
+               # Return the address.
+               return $1;
+       }
+
+       # Unable to grab the address - Return nothing.
+       return;
+}
+
 1;