From 5a41d1c265920c0b6402f59a34dbc40282c3b9ee Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 24 Nov 2025 08:11:13 +0100 Subject: [PATCH] Add script to fetch public IP from multiple providers This script attempts to retrieve the public IP address by querying multiple services in a randomized order. If successful, it writes the IP to /currentip; otherwise, it outputs an error message. --- qbittorrent/rootfs/etc/helpers/public_ip.sh | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 qbittorrent/rootfs/etc/helpers/public_ip.sh diff --git a/qbittorrent/rootfs/etc/helpers/public_ip.sh b/qbittorrent/rootfs/etc/helpers/public_ip.sh new file mode 100644 index 000000000..262e04823 --- /dev/null +++ b/qbittorrent/rootfs/etc/helpers/public_ip.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +get_public_ip() { + local urls=( + "https://ifconfig.co/ip" + "https://api64.ipify.org" + "https://ipecho.net/plain" + ) + local i j tmp url ip + + # Fisher–Yates shuffle to randomize the order + for ((i=${#urls[@]}-1; i>0; i--)); do + j=$((RANDOM % (i + 1))) + tmp=${urls[i]} + urls[i]=${urls[j]} + urls[j]=$tmp + done + + # Try each provider in random order until one works + for url in "${urls[@]}"; do + if ip=$(curl -fsS --max-time 10 "$url"); then + printf '%s\n' "$ip" + return 0 + fi + done + + return 1 +} + +# Write to /currentip, fail if none of the services respond +if ! get_public_ip > /currentip; then + echo "Failed to get public IP from all providers" >&2 +fi