Skip to content

Instantly share code, notes, and snippets.

@oakaigh
Last active March 24, 2019 04:19
Show Gist options
  • Save oakaigh/7646fdc39bc994f972f98591a2466b64 to your computer and use it in GitHub Desktop.
Save oakaigh/7646fdc39bc994f972f98591a2466b64 to your computer and use it in GitHub Desktop.
POSIX-compatible DNS lookup function
gethostbyname() {
for d in $@; do
address=$(nslookup $d | awk -F: '/Name.*/ { flag = 1; next }
/Address.*/ && flag { print $NF }' | awk '{ print $1 }')
echo ${address:-$d}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment