#! /bin/sh # (Bourne shell script) -- reports on mail exchangers for a domain # # The command "host -t mx example.com" can give no response (a blank line) # if there are no MX records, or the following: # moo.com mail is handled by 6 us-mx.moo.com. # moo.com mail is handled by 5 mx.moo.com. # Note: this command is partly redundant, given the following example: # $ host ausmedsupply.com.au # ausmedsupply.com.au has address 203.82.212.50 # ausmedsupply.com.au mail is handled by 50 email.webvault.com.au. # ausmedsupply.com.au mail is handled by 100 mail2.webvault.com.au. # TO-DO: catch and report the error filtered out by the grep # (first two are fatal and indicate domain problems; 3rd one means that # fqdn handles its own mail) set -e host -t mx "$@" | grep -v -e 'NXDOMAIN' -e 'connection timed out' -e 'has no MX record' | sort -k6n | while read a b c d e n mx blah ; do host=$(host $mx | head -n 1) echo "$host (priority $n)" set $host # If result is an IP address, reverse-resolve it if expr "$4" : '^[0-9]' > /dev/null then echo "$(host $4)" | sed 's/^.* \([^ ]*\)\.$/ \1/' fi done