首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用多个域名和IP进行DNS检查

使用多个域名和IP进行DNS检查
EN

Stack Overflow用户
提问于 2017-05-23 22:11:49
回答 1查看 97关注 0票数 0

我正在构建一个脚本,它检查服务器上的各种潜在问题,我有一个部分,它应该检查服务器上的所有域针对该服务器的摘要,并检查域是否指向服务器的IP。

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

以下是脚本的相关部分:

代码语言:javascript
运行
复制
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
}
EN

回答 1

Stack Overflow用户

发布于 2017-05-24 18:31:20

对于任何对未来感兴趣的人,这里有一个解决方案:

代码语言:javascript
运行
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44137211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档