From: Stefan Schantl Date: Fri, 18 Apr 2025 10:54:41 +0000 (+0200) Subject: http-client-functions.pl: Add FetchPublicIP function. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ad67364213cb37179a4973d2c3d8492be0b6ec8;p=ipfire-2.x.git http-client-functions.pl: Add FetchPublicIP function. 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 Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/http-client-functions.pl b/config/cfgroot/http-client-functions.pl index 26ead6908..bfb9fdd20 100644 --- a/config/cfgroot/http-client-functions.pl +++ b/config/cfgroot/http-client-functions.pl @@ -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;