我目前正在尝试编写一个脚本来validation通过所有负责该名称的名称服务器是否可以使用附加到名称的给定logging。
例如,我想检查在example.com域的所有NS条目( a.iana-servers.net和b.iana-servers.net )上是否存在foo.example.com的Alogging。
该脚本通过首先查询NSlogging为给定的名字(或其父母如果失败;例如,因为foo.example.com.没有NS条目,我们尝试example.com.和finally .com. ,然后用所有名称服务器检查Alogging。
name=foo.example.com # get the nameservers for ${name} sname=${name} until [ -z "x${sname}" ]; do dns=$(dig +short NS "${sname}") if [ "x${dns}" != "x" ]; then break fi sname=${sname#*.} done # now that we have a list of nameservers in $dns, we query them for ns in $dns; do dig +short A "${name}" @$"{ns}" done
这种作品, 除非这个名字实际上是一个CNAME 。 在这种情况下, dig NS会返回CNAMElogging(而不是NSlogging或不logging)
$ dig +noall +answer NS foo.example.com foo.example.com. 300 IN CNAME bar.example.com. $ dig +short NS foo.example.com bar.example.com. $ dig A foo.example.com @bar.example.com ;; global options: +cmd ;; connection timed out; no servers could be reached $
相反,我想有这样的东西:
$ dig +short NS foo.example.com $ dig +short NS example.com a.iana-servers.net. b.iana-servers.net. $ dig +short A foo.example.com @a.iana-servers.net. 93.184.216.34 $
所以我的问题是:我如何强制dig 只返回NSlogging,而不是其他指向不是名称服务器的主机的其他logging?
一个明显的解决scheme是parsingdig +noall +answer的输出,看它是否实际上包含一个NSlogging,但这看起来相当笨拙和容易出错…
如果您对Perl感到满意,可以将您的testing作为插件写入Zonemaster ,从而为您节省大量相当挑剔的工作。 它的框架已经有(正确的)代码来find正确的名称服务器集合并向它们发送查询。