DNS检查多个域和IP

时间:2017-05-23 14:11:49

标签: bash unix dns

我正在构建一个脚本,用于检查服务器上的各种潜在问题,我有一个部分,它应检查服务器上的所有域,以防止挖掘该服务器并检查域是否指向服务器' s IP

所有命令在独立运行时按预期工作,但脚本输出的域仅针对一个IP进行检查。

以下是该脚本的相关部分:

checkDomainDNS()    {                                   
if [ "$controlPanelVersion" == "Plesk" ]; then
serverIPs=()
for ips in $(ifconfig | grep "inet addr:" | cut -d":" -f2 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -v '127.0.0.*\|0.0.0.0\|3.0.13.6');do
let count++
serverIPs[count - 1]+=$ips
done
    domainsArray=()
        for domain in $(MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e"SELECT dom.id, dom.name, ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId" | cut -d"|" -f3 | awk '{print $2}'); do
        let count++
        domainsArray[count - 1]+=$domain
        done
            for domain in ${domainsArray[*]};do
                dnsResult=()
                for dnsResult in $(dig A $domain | grep $domain | awk '{print $5}' | grep -v "<<>>" | sed '/^$/d' | grep -v "ns");do
                let count++
                dnsResult[count - 1]+=$dnsResult
                done
            done
                for i in ${serverIPs[*]};do
                    if [ "$dnsResult" == "$ips[*]" ]; then
                        echo "$domain is pointed correctly" >> $reportlog
                    elif [ "$dnsResult" != "$ips[*]" ]; then
                        echo "$domain is not pointed to $ips" >> $reportlog
                    fi
                done
fi
}

1 个答案:

答案 0 :(得分:0)

对于对未来感兴趣的任何人都是决议:

checkDomainDNS()    {

                                                                                                                                                                                                                                echo "Checking domain DNS records"
                                                                                                                                                                                                                                if [ "$controlPanelVersion" == "Plesk" ]; then
                                                                    domainsArray=()
        for domain in $(MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e"SELECT dom.id, dom.name, ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId" | cut -d"|" -f3 | awk '{print $2}' | grep -Ev "name"); do
                                                                let count++
                                                                domainsArray[count - 1]+=$domain
                                                                done
                                                                serverIPs=()
                                                       for ips in $(ifconfig | grep "inet addr:" | cut -d":" -f2 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -v '127.0.0.*\|0.0.0.0\|3.0.13.6');do
                                                                        let count++
                                                                        serverIPs[count - 1]+=$ips
                                                                        done
                                                                            for domain in ${domainsArray[*]};do
                                                                            pointing="no"
                                                                            dnsResult=$(dig A $domain | grep $domain | awk '{print $5}' | grep -v "<<>>" | sed '/^$/d' | grep -v "ns")
                                                                            for i in ${serverIPs[*]};do
                                                                            if [ "$dnsResult" == "$i" ]; then
                                                                            pointing="yes"
                                                                            break
                                                                            fi
                                                                            done
                                                                        if [ $pointing == "no" ]; then
                                                                            echo "$domain is not pointed towards this server" >> $reportlog
                                                                        fi
                                                                        done
                                                          else
                                                          echo "Checking dns only works on Plesk servers" >> $reportlog
                                                        fi
}