From patchwork Fri Apr 18 10:54:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 8613 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4ZfC182SDMz3wb5 for ; Fri, 18 Apr 2025 11:18:04 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "E5" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4ZfC161Mpcz3N7 for ; Fri, 18 Apr 2025 11:18:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4ZfC1560vdz337b for ; Fri, 18 Apr 2025 11:18:01 +0000 (UTC) X-Original-To: development@lists.ipfire.org Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4ZfC126C7Jz336p for ; Fri, 18 Apr 2025 11:17:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4ZfC1211ylz2yn; Fri, 18 Apr 2025 11:17:58 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1744975078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KIaaJAJxnhPQczA6FFCL5OC7kP89UPy3POzTNjCaKns=; b=Eu9tXWMpMa2PBkEMyxFBFJg8Poy1O81q4w5ewy3OU5g5aVYW9dHkFsh+qYJoKeknUPj4i3 o+IIY6bscFw6gYAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1744975078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KIaaJAJxnhPQczA6FFCL5OC7kP89UPy3POzTNjCaKns=; b=ns0pVkX37JGIA162LdLtiRIS5zTW/JEAUHuigGq4SuwEIU3SkAByiQGiT1HH6AtXsJz1uH JHV7EcwRimeo4G8r46rbC5piFx2FyRY5CzLROiOG276LwIJzU1oIvHgnYq2Hs+aUPrx39Y Gh9P/xyaL/AQVN6QhS6KXMRnHSEKYEXY8JwNT3EI515RMNbeuEgU+KBv/fzCiDuJAMpj14 O/g6ET/i0tBiHub+3x8TIulRKgp6aq+o/xPmHI+EFZnylKThJOi2QRCorQeASyHz+SoMBw UHG9ndWrI81y3DkaIFpKLj23nWE6oHK+MaRgg10JRzYw/iDulB1uDhbidQn7xQ== From: Stefan Schantl To: development@lists.ipfire.org Cc: Stefan Schantl Subject: [PATCHv2 2/7] http-client-functions.pl: Add FetchPublicIP function. Date: Fri, 18 Apr 2025 12:54:41 +0200 Message-ID: <20250418110741.7756-3-stefan.schantl@ipfire.org> In-Reply-To: <20250418110741.7756-1-stefan.schantl@ipfire.org> References: <20250418110741.7756-1-stefan.schantl@ipfire.org> Precedence: list List-Id: List-Subscribe: , List-Unsubscribe: , List-Post: List-Help: Sender: Mail-Followup-To: MIME-Version: 1.0 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 --- config/cfgroot/http-client-functions.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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;