From f695c4331185fafe182d746ee6dbfdf07c902041 Mon Sep 17 00:00:00 2001 From: The_Spider Date: Mon, 28 Mar 2022 11:57:26 -0500 Subject: [PATCH] adds more methods to get public ip address in case one method is not available. --- build-deluge.jenkins | 65 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/build-deluge.jenkins b/build-deluge.jenkins index 33cd7bf..ded333a 100644 --- a/build-deluge.jenkins +++ b/build-deluge.jenkins @@ -13,31 +13,68 @@ printf "%s\n" "Route Updated" """ def connectivity_test = """#! /usr/bin/env sh +getPublicIP() { + ip="" + + # curl lookups + for i in "https://icanhazip.com" "https://ifconfig.me" "https://api.ipify.org" "https://bot.whatismyipaddress.com" "https://ipinfo.io/ip" "https://ipecho.net/plain"; do + ip=\$(curl -s "${i}") + if [ "\${ip}" != "" ]; then + printf '%s' "\${ip}" + return 0 + fi + done + + # DNS Lookups + ip=\$(dig -4 @ns1.google.com TXT o-o.myaddr.l.google.com +short | sed -e 's/"//g') + if [ "\${ip}" != "" ]; then + printf '%s' "\${ip}" + return 0 + fi + + ip=\$(dig -4 @resolver1.opendns.com A myip.opendns.com +short | sed -e 's/"//g') + if [ "\${ip}" != "" ]; then + printf '%s' "\${ip}" + return 0 + fi + + ip=\$(dig -4 @1.0.0.1 txt ch whoami.cloudflare +short | sed -e 's/"//g') + if [ "\${ip}" != "" ]; then + printf '%s' "\${ip}" + return 0 + fi +} + if ! curl --silent --fail --insecure http://localhost:8112 > /dev/null; then - printf '%s\\n' "Deluge not running." - exit 100 + printf '%s\\n' "Deluge not running." + exit 100 fi + if [ -z "\${DDNS_HOST}" ] || [ "\${DDNS_HOST}" = "" ]; then - printf '%s\\n' "Dynamic DNS host is not set." - exit 100 + printf '%s\\n' "Dynamic DNS host is not set." + exit 100 fi -DIP=\$(dig -4 @ns1.google.com TXT o-o.myaddr.l.google.com +short | sed -e 's/"//g') + +DIP=\$(getPublicIP) if [ -z "\${DIP+x}" ] || [ "\${DIP}" = "" ]; then - printf '%s\\n' "Unable to detect real-world IP." - exit 100 + printf '%s\\n' "Unable to detect real-world IP." + exit 100 fi + KIP=\$(dig "\${DDNS_HOST}" +short) if [ -z "\${KIP+x}" ] || [ "\${KIP}" = "" ]; then - printf '%s\\n' "Unable to get known IP." - exit 100 + printf '%s\\n' "Unable to get known IP." + exit 100 fi + if [ "\${DIP}" = "\${KIP}" ]; then - printf '%s\\n' "VPN is not functional." - exit 100 + printf '%s\\n' "VPN is not functional." + exit 100 fi + if ! ping -c 2 google.com > /dev/null; then - printf '%s\\n' "No internet connectivity." - exit 100 + printf '%s\\n' "No internet connectivity." + exit 100 fi """ @@ -46,7 +83,7 @@ LABEL maintainer="The_Spider " COPY route-override.sh connectivity_test.sh /root/ -RUN apk add --no-cache openvpn iputils bind-tools && \\ +RUN apk add --no-cache openvpn iputils bind-tools curl && \\ chmod +x /root/route-override.sh /root/connectivity_test.sh """