Skip to content

Instantly share code, notes, and snippets.

@SalemHarrache
Created April 17, 2020 14:17
Show Gist options
  • Save SalemHarrache/bb299f6a362943fc11366b43107d34e1 to your computer and use it in GitHub Desktop.
Save SalemHarrache/bb299f6a362943fc11366b43107d34e1 to your computer and use it in GitHub Desktop.
_resolv_domain_name() {
if _cmd_exists dscacheutil; then
# Mac OSX
dscacheutil -q host -a name "$1" | grep ip_address | cut -d ":" -f2 | head -n 1 | xargs
elif _cmd_exists dig; then
dig A +short "$1" | head -n 1 | xargs
elif _cmd_exists nslookup; then
# exclude IPV6
nslookup "$1" | awk '/^Address: / { print $2 }' | grep -Eo '[0-9\.]{7,15}' | head -n 1 | xargs
elif _cmd_exists host; then
# exclude IPV6
host "$1" | awk '/has address/ { print $4 }' | head -n 1 | xargs
else
# exclude IPV6
getent ahosts "$1" | grep -Eo '[0-9\.]{7,15}' | awk '{ print $1 }' | head -n 1 | xargs
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment