Skip to content

Instantly share code, notes, and snippets.

@sgraham785
Created January 21, 2015 20:12
Show Gist options
  • Save sgraham785/244ba6f81c484fc072ff to your computer and use it in GitHub Desktop.
Save sgraham785/244ba6f81c484fc072ff to your computer and use it in GitHub Desktop.
Dig domains from txt file
#!/bin/bash
## HOW TO USE
# sh dig_domains.sh A "8.8.8.8" (this returns the A records)
# domain.com 1224 IN A 127.0.0.1
# sh dig_domains.sh A "8.8.8.8" "mail." (returns the mail. subdomain A records)
# mail.domain1.com. 14399 IN CNAME domain1.com.
# mail.domain2.com. 3599 IN A 127.0.0.1
# sh dig_domains.sh MX "8.8.8.8" | awk '{print substr($1, 1, length($1)-1), "\t" substr($6, 1, length($6)-1)}'
# domain.com smtp.secureserver.net
# sh dig_domains.sh A "8.8.8.8" | awk '{print substr($1, 1, length($1)-1), "\t" substr($5, 1, length($5))}'
# domain.com 127.0.0.1
## START SCRIPT
for domain in `cat /path/to/file.txt`
do
NS=$2
PREFIX=$3
TASK=$1
domain=$3$domain
#dig @$NS $domain $TASK
# host $domain
dig @$NS $domain $TASK | grep -A 1 ";; ANSWER" | grep -v -e ";; ANSWER"
#sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment