问题原文
原帖链接 · Alex · CC BY-SA 4.0
The behavior of dig +short is to return nothing (null) when running a query that returns no answer (nothing to do with the timeout, just a definite null answer).
It is ok when running a query by itself, but when combining with an -f parameter and running a batch of queries, it is terrible!
dig +short -f queries.txt
queries.txt:
A somedomain.com
TXT otherdomain.com
A somedomain.com
Now, if the DNS server returns nothing for TXT otherdomain.com (i.e., ANSWER: 0), not timeout or something else, then the output of the above dig command will be something like:
dig +short -f queries.txt
1.2.3.4
1.2.3.4
i.e., only two lines. Not suitable for "paste" and other similar commands. You can no longer merge the output of queries.txt and the production output of dig.
Anything elegant can be done here?
已采纳解答
原帖链接 · Andrew B · CC BY-SA 3.0
There is no real way to make +short do what you want it to in this context. It's simply the wrong tool for the job when working with bulk data.
The solution I found when running into this problem was to use a combination of filters: +noall +question +answer. +noall turns all display fields off, +question displays the query being made with a ; comment prefix, and +answer displays the answer.
The output looks like this:
$ dig +noall +question +answer google.com serverfault.com
;google.com. IN A
google.com. 284 IN A 74.125.137.101
google.com. 284 IN A 74.125.137.138
google.com. 284 IN A 74.125.137.102
google.com. 284 IN A 74.125.137.100
google.com. 284 IN A 74.125.137.113
google.com. 284 IN A 74.125.137.139
;serverfault.com. IN A
serverfault.com. 187 IN A 198.252.206.16
In the event that you get no response back, you will see two adjacent questions. You won't know why the query failed as this output doesn't display a RCODE (neither does +short), but the output is sufficient for analyzing a bulk data set and locating records that need more verbose analysis.
If you find yourself doing bulk analysis of DNS referrals, switch +answer out for +authority.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
