问题
I am trying to combine a batch search for some DNS records search with Whois search on my terminal. I have a CSV file with a list of domains and I would like to run the following batch searchers:
- MX search:
host -t mx $domain
- NS search:
host -t ns $domain
This are pretty easy.
Combine this with Whois Search ; Which returns only a summary of some of the Whois data;I would need to query the whois server for the domain which is fine like: whois
I can use -h
, to only record Domain Registrant Details such as Telephone, Country code etc. I have tried this:
- Whois:
whois -h 'Registrar WHOIS Server:' "domain"
Which gives me the output as well for only Registrant details.
So when I combine all into a single bash file, I get:
#!/usr/bin/env bash
file="${1:-input_test1.csv}"
if [[ ! -f "$file" ]]; then
printf 'No file: %s\n' "$file" >&2
exit 1
fi
(
read -r header; printf '%s\n' "$header"
while IFS=, read -r domain; do
mx="$(host -t mx "$domain" | sort | head -1)"
ns="$(host -t ns "$domain" | sort| head -1)"
whois="$(whois -h "$(whois" "$domain" | grep 'Registrar WHOIS Server:') "$domain")
printf '%s,"%s"\n' "$domain" "$mx" "$ns" "$whois"
done
) < "$file"
I would love to get a CSV output with the domain, mx (only 1), NS (only 1), whois whois is registrant data s shown below;
Sample Expected Output Screengrab
Thank you.
回答1:
You already know that different domains point to different whois servers. I think you are going to find that each registrar has their own favourite way of presenting information via whois, and that they are not consistent. ICANN mandates that a minimum set of data be available via whois, but some of the data you're looking for may fall outside that set.
The following strips just basic data from whois.internic.net, which you can use for gathering DNS servers, whois servers and MX:
#!/usr/bin/env bash
mapfile -t domains < domains.lst
declare -i i
for this in "${domains[@]}"; do
unset a; declare -A a=()
unset ns; declare -a ns=()
whois=""
i=0
while IFS=: read -r key value; do
#printf "key=%s / value=%s\n" "$key" "$value"
case "$key" in
*"Registrar WHOIS Server") whois="${value## }" ;;
*"Name Server") ns+=("${value## }") ;;
esac
done < <(whois -h whois.internic.net "$this")
read mx < <(host -t mx "$this" | sort | awk 'NR==1{print $NF}')
printf '%s,%s,%s,%s\n' \
"$this" \
"$mx" \
"$whois" \
"$(printf '%s ' "${ns[@]}")"
done
If you really want to try to scrape from the whois data at $whois
, the script above should show you how you might be able to do that for each domain in your list.
来源:https://stackoverflow.com/questions/54197993/run-batch-dns-whois-search-on-terminal-with-output