diff --git a/ifpublic/ifpublic b/ifpublic/ifpublic index 649d408..4cade4d 100755 --- a/ifpublic/ifpublic +++ b/ifpublic/ifpublic @@ -1,16 +1,24 @@ #!/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 +: HTTP APIs that return your public IP address [both v4 and v6] "\ +https://icanhazip.com +https://ifconfig.io +http://icanhazip.com +http://ifconfig.io/ +" + +PUBLIC_IP_FETCH_URL="https://icanhazip.com" +PUBLIC_IP6_FETCH_URL="$PUBLIC_IP_FETCH_URL" + +pscat \ + [ curl -4 --connect-timeout 5 --silent "$PUBLIC_IP_FETCH_URL" \ + ] \ + [ printf ' / ' ] \ + [ curl -6 --connect-timeout 5 --silent \ + "$PUBLIC_IP6_FETCH_URL" ] \ + | tr -d '\n' \ + | xargs echo \ + | sed 's/ \/$//g' \ + | sed 's/^\/ //g' + exit 0