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.