From bf6e5e85ee020ecf951ce444409fa24f3c6c37e1 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 22 Aug 2024 10:50:09 -0700 Subject: [PATCH] getip and publicip refactored to have not dependencies used in geip in sshd-dns --- modules/net-utils.mod | 16 +++++++++++++--- modules/sshd-dns.mod | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/net-utils.mod b/modules/net-utils.mod index 88ca4bb..b891b6d 100644 --- a/modules/net-utils.mod +++ b/modules/net-utils.mod @@ -102,14 +102,24 @@ domain=$(echo $1 | awk -F\. '{print $(NF-1) FS $NF}') echo "$domain" } +#https://stackoverflow.com/a/44191743 +#https://blog.apnic.net/2021/06/17/how-a-small-free-ip-tool-survived/ publicip () { -dig +short myip.opendns.com @resolver1.opendns.com +# if which curl >/dev/null 2>&1; then if curl ipinfo.io/ip 2> /dev/null; then return; fi fi +# if which dig>/dev/null 2>&1; then if dig +short myip.opendns.com @resolver1.opendns.com 2> /dev/null; then return; fi fi +exec 3<>/dev/tcp/icanhazip.com/80 +echo -e 'GET / HTTP/1.0\r\nhost: icanhazip.com\r\n\r' >&3 +while read i +do + [ "$i" ] && myip="$i" +done <&3 +echo "$myip" } getip () { [[ ! $1 ]] && return 1 -if ip=$(host -4 -t A $1); then -echo $ip | awk '{print $NF}' +if ip=$(getent ahostsv4 $1); then +echo $ip | grep STREAM | '{ print $1 ; exit }' else return 2 fi diff --git a/modules/sshd-dns.mod b/modules/sshd-dns.mod index d926552..d14a927 100644 --- a/modules/sshd-dns.mod +++ b/modules/sshd-dns.mod @@ -9,8 +9,8 @@ local conf _getip () { [[ ! $1 ]] && return 1 -if ip=$(host -4 -t A $1); then -echo $ip | awk '{print $NF}' +if ip=$(getent ahostsv4 $1); then +echo $ip | grep STREAM | '{ print $1 ; exit }' else return 2 fi