-
Notifications
You must be signed in to change notification settings - Fork 2
/
lookup.sh
32 lines (24 loc) · 1.1 KB
/
lookup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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,Nameserver,Nameserver,Nameserver,Nameserver,Nameserver" > 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,$ns" >> domains.csv
# Defines the text file from which to read domain names
done < domains.txt