From 210054fe8b9634a647b55a7c75e2a1cf5df0a784 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 8 May 2024 19:54:51 -0600 Subject: [PATCH] Scripts: update myip script for wan --- bin/myip | 70 ++++++++++++-------------------------------------------- 1 file changed, 14 insertions(+), 56 deletions(-) diff --git a/bin/myip b/bin/myip index a228b22..23e7ecb 100755 --- a/bin/myip +++ b/bin/myip @@ -2,66 +2,24 @@ # List system's WAN and LAN ip addresses # Depends on ifconfig and awk -if [[ $1 =~ '-h' ]]; then - cat < /dev/null; then - ip address | awk_lan 'substr(info[2], 2)' -elif command -v ifconfig &> /dev/null; then - ifconfig | awk_lan 'info[1]' +if [[ -n "$ipv4" ]]; then + echo "IPv4 (WAN): $ipv4" else - echo '`ifconfig` not found' + echo "IPv4 (WAN): Not available" fi -# Print network's public IP address -if command -v dig &> /dev/null; then - public_ip=$(dig +short myip.opendns.com @resolver2.opendns.com) -elif command -v host &> /dev/null; then - public_ip=$(host myip.opendns.com resolver1.opendns.com) -fi +declare -r ipv6="$(curl --max-time 1 -s https://api6.ipify.org)" -# Backup address fetching. Slower though more reliable -if [[ -z $public_ip ]]; then - if command -v curl &> /dev/null; then - public_ip=$(curl --silent https://ifconfig.me/ip) - elif command -v wget &> /dev/null; then - public_ip=$(wget --quiet -O - https://ifconfig.me/ip) - fi -fi - - -if [[ -n $public_ip ]]; then - echo "$public_ip" | awk ' match($0, /([0-9]{1,3}\.){3}[0-9]{1,3}$/) { - printf("Public (WAN): %s\n", substr($0, RSTART, RLENGTH)) - }' +if [[ -n "$ipv6" ]]; then + echo "IPv6 (WAN): $ipv6" else - echo 'Public IP not found' + echo "IPv6 (WAN): Not available" +fi + +declare -r ipv64="$(curl --max-time 1 -s https://api64.ipify.org)" + +if [[ -n "$ipv64" ]]; then + echo "First Resolved: $ipv64" fi