Created
October 26, 2014 22:35
-
-
Save jhead/8a9b544d9d0632544109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ITER=5 | |
## | |
function usage { | |
echo "Usage: resolve [options] hostname" | |
echo | |
echo -e " -t #\t\tSpecify number of lookups (default 5)" | |
exit | |
} | |
function query { | |
local FQDN | |
local TRIES | |
local DATA | |
FQDN=$1 | |
TRIES=$2 | |
echo -n "Resolving $FQDN over $TRIES tries... " | |
DATA="" | |
i=0 | |
while [ $i -lt $TRIES ]; do | |
HOST=$(host $FQDN | grep 'has address' | awk '{print $4}') | |
DATA=$(echo -e "$DATA\n$HOST") | |
DATA=$(echo "$DATA" | sort | uniq | sed '/^$/d') | |
i=$((i+1)) | |
done | |
COUNT=$(echo "$DATA" | wc -l | awk '{print $1}') | |
echo "Done!" | |
echo | |
echo "$DATA" | |
echo | |
echo "Found $COUNT addresses associated with $FQDN" | |
} | |
## | |
## Parse params | |
if [ "$#" -lt 1 ]; then | |
usage | |
fi | |
while getopts ":t:" opt; do | |
case "${opt}" in | |
t) ITER=$OPTARG | |
;; | |
*) usage | |
;; | |
esac | |
done | |
## | |
HOST="${@: -1}" | |
query $HOST $ITER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment