-
-
Save maesoser/43555439975012e1409f11ce8db19457 to your computer and use it in GitHub Desktop.
sdig is a dig wrapper that adds some common options and query multiple entries at once
This file contains 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
#!/usr/bin/env bash | |
DEFAULT_RESOLVER="1.0.0.1" | |
do_dig () { | |
ENTRYTYPES="A AAAA CAA CNAME MX NS PTR SOA SRV TXT DS DNSKEY RRSIG PTR SRV TLSA HINFO NSEC NSEC3 NSEC3PARAM SSHFP type65" | |
for type in $ENTRYTYPES; do | |
out=$(dig +noall +dnssec +answer $1 $2 $type | awk '{gsub("IN\t", "", $0); print}') | |
colorize "$out" | |
done | |
echo -e "\nFrom $1" | |
} | |
colorize () { | |
echo "$@" | awk \ | |
-v black="$(tput setaf 0)" \ | |
-v red="$(tput setaf 1)" \ | |
-v green="$(tput setaf 2)" \ | |
-v yellow="$(tput setaf 3)" \ | |
-v blue="$(tput setaf 4)" \ | |
-v magenta="$(tput setaf 5)" \ | |
-v cyan="$(tput setaf 6)" \ | |
-v white="$(tput setaf 7)" \ | |
-v reset="$(tput sgr0)" \ | |
-v dim="$(tput dim)" \ | |
-v bold="$(tput bold)" \ | |
'{ | |
if ($0 ~ "\tA") color=green; | |
else if ($0 ~ "CNAME") color=yellow; | |
else if ($0 ~ "MX") color=blue; | |
else if ($0 ~ "NS") color=magenta; | |
else if ($0 ~ "SOA") color=cyan; | |
else if ($0 ~ "PTR") color=green; | |
else if ($0 ~ "TXT") color=red; | |
else color=dim | |
if ( length($0)!=0) printf "%s%s%s\n", color, $0, reset; | |
}' | |
} | |
if [[ $# == 1 ]]; then | |
do_dig "@${DEFAULT_RESOLVER}" $1 | |
exit | |
fi | |
if [[ $# == 2 ]]; then | |
do_dig "@${1}" "${2}" | |
exit | |
fi | |
echo -e "Usage:\n\tsdig <domain>\n\tsdig <resolver> <domain>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment