#!/bin/bash
function whodig() {
        if [ -n "$1" ]; then
                echo
                echo A record
                ips=$(dig $1 a +short)
                firstip=$(echo $ips | cut -d " " -f1)
                echo $ips
                echo
                echo name servers
                dig $1 ns +short
                echo
                echo mail records
                dig $1 mx +short
                echo
                whois $1 | grep -oP 'Registrar:\s+\w+'
                echo
                firstiplen=$(echo $firstip | wc -m)
                if [[ $firstiplen -gt 1 ]]; then
                        echo Reverse
                        dig -x $firstip | grep -A1 AUTHORITY | tail -n1 | cut -f5 | cut -d " " -f1
                        host $firstip
                        echo
                fi
        else
                echo "usage: whodig <domain name>"
        fi
}
whodig $1
