resolve CNAME to IP

master
David Kebler 2024-04-29 14:16:07 -07:00
parent f4faa105a3
commit 484f5f0c28
1 changed files with 20 additions and 3 deletions

View File

@ -59,7 +59,7 @@ rsynchg() { rsync --help | grep "\-$1"; }
gip () { gip () {
if which jq &> /dev/null; then if which jq &> /dev/null; then
curl -s "https://dns.google/resolve?name=$1" | jq -r '.Answer[] | .data' curl -s "https://dns.google/resolve?name=$1" | jq -r '.Answer[] | .data' | tail -n 1
return 0 return 0
else else
echo install jq to use this function echo install jq to use this function
@ -72,6 +72,23 @@ gpip () {
} }
dip () { valid_ipv4() {
/bin/drill $1 | grep -A1 'ANSWER SECTION' | grep -v "ANSWER SECTION" | rev | cut -f1 | rev local ip="$1"
[[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || return 1
for i in ${ip//./ }; do
[[ "${#i}" -gt 1 && "${i:0:1}" == 0 ]] && return 1
[[ "$i" -gt 255 ]] && return 1
done
return 0
} }
dip () {
local ip4
ip4=$(/bin/drill $1 | grep -A1 'ANSWER SECTION' | grep -v "ANSWER SECTION" | rev | cut -f1 | rev)
# echo first: $ip4
if valid_ipv4 $ip4; then
echo $ip4
else
/bin/drill $ip4 | grep -A1 'ANSWER SECTION' | grep -v "ANSWER SECTION" | rev | cut -f1 | rev
fi
}