One of our customers moved to a new spam filter platform. For this we needed to get an overview of the ip addresses of the mailserver the domains currently used. Instead of doing this manually I created a quick script to do this. It reads the domains from a file (domains.txt) in the current directory and outputs the domains and ip addresses as a tabbed line. This makes it easy to import in Excel.

while read line
myline=`echo -n $line | tr -d "\n"`
output=`dig +short $myline mx | sort -n | awk -v pref=65536 '($1<=pref) {pref=$1; print $2}' | dig +short -f - | uniq` myoutput=`echo -n $output | tr -d "\n"` echo -e "$myline \t $myoutput" done < domains.txt

$ ./ > domains-mx-ip.csv

Leave a reply