From 06dfa3de172b58bea8412464cf0ab6b4ebc0003a Mon Sep 17 00:00:00 2001 From: dtb Date: Fri, 21 Oct 2022 13:35:40 -0400 Subject: [PATCH] ifpublic(1) --- ifpublic/ifpublic | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 ifpublic/ifpublic diff --git a/ifpublic/ifpublic b/ifpublic/ifpublic new file mode 100755 index 0000000..649d408 --- /dev/null +++ b/ifpublic/ifpublic @@ -0,0 +1,16 @@ +#!/bin/sh + +PUBLIC_IP4="$(curl -4 --connect-timeout 5 "$PUBLIC_IP_FETCH_URL" --no-progress-meter 2>/dev/null \ + || printf "-1")" +PUBLIC_IP6="$(curl -6 --connect-timeout 5 "$PUBLIC_IP6_FETCH_URL" --no-progress-meter 2>/dev/null \ + || printf "-1")" +if [ "$PUBLIC_IP4" = "-1" ] && [ "$PUBLIC_IP6" = "-1" ]; then + printf "[error fetching address]" +elif [ "$PUBLIC_IP4" = "-1" ]; then + printf "%b" "$PUBLIC_IP6" +elif [ "$PUBLIC_IP6" = "-1" ]; then + printf "%b" "$PUBLIC_IP4" +else + printf "%b / %b" "$PUBLIC_IP4" "$PUBLIC_IP6" +fi +exit 0