-
-
Save anthonygtellez/394d234bc75e39c3473ef4f7749bfcf1 to your computer and use it in GitHub Desktop.
Lookup A-record and Nameservers for a list of domains in a txt file, output into a csv file
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
#!/bin/bash | |
# Put all the domain names in domains.txt, one per line | |
# then run in the terminal: bash domains.sh | |
# this will print each domain in the terminal as it looks it up | |
# The result csv will contains the domain, IP & Nameservers in each column | |
# Give each column the relevant header titles | |
echo "Domain Name,IP Address" > dig_cloud-bleed_domains.csv | |
while read domain | |
do | |
# Get IP address defined in domain's root A-record | |
ipaddress=`dig $domain +short` | |
# Get list of all nameservers | |
ns=`dig ns $domain +short| sort | tr '\n' ','` | |
# Use the line below to extract any information from whois | |
# ns=`whois $domain | grep "Name Server" | cut -d ":" -f 2 | sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'` | |
echo "$domain" | |
# Uncomment the following lines to output the information directly into the terminal | |
# echo "IP Address: $ipaddress" | |
# echo "Nameservers: $ns" | |
# echo " " | |
# Prints all the values fetched into the CSV file | |
echo -e "$domain,$ipaddress" >> dig_cloud-bleed_domains.csv | |
# Defines the text file from which to read domain names | |
done < my_cloud-bleed_domains.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment