amy
amy

Reputation: 185

Script To Look Up Nameservers On Multiple Domains

I am working on migrating a customer's WHM / cPanel account to a new server, however he has many, many sites hosted on the server that I need to retrieve their nameservers.

I'd like to create a bash script that parses a file (with each domain on a separate line), performs a dig and whois, finds the nameserver and IP, and then outputs the domain and its nameserver to another file.

I'm not very good with bash, but I have found and edited this script - but it doesn't seem to want to work at all. If anyone has any insight, that would be great. Thanks!

#!/bin/bash
# dig $line +short >> ip address 
# whois $line >> Lists full details including the name servers 
# whois $line | grep "Name Server" | cut -d ":" -f 2 | sed 's/ //' | 
# sed -e :a -e '$!N;s/ \n/,/;ta'`  
while read inputfile 
do 
echo $domain  
ipaddress=`dig $domain +short` 
nameserver=`whois $domain | grep "Name Server" | cut -d ":" -f 2 |    
sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'` 
echo -e "$domain,$ipaddress,$nameserver" >> outputfile
done

Upvotes: 0

Views: 5388

Answers (1)

madz
madz

Reputation: 1863

This will output all possible A and NS records of domains in given file:

#!/bin/bash
while read domain 
do 

for a in `dig $domain a +short`
do
    ipaddress="$ipaddress$a,"
done

for ns in `dig $domain ns +short`
do
    nameserver="$nameserver$ns,"
done 
echo "$domain,$ipaddress,$nameserver"
done

usage

Suppose script is named as resolver and the file is input. Do

cat input | ./resolver

(Some domains have more than one ip addresses and name servers)

Upvotes: 1

Related Questions