问题原文
原帖链接 · pabouk - Ukraine stay strong · CC BY-SA 4.0
With default options dig shows the return status for a DNS query in the comment ;; ->>HEADER<<- ... status: NXDOMAIN:
ubuntu:~$ dig hosted-by.myinternetservices.com.
; <<>> DiG 9.11.3-1ubuntu1.2-Ubuntu <<>> hosted-by.myinternetservices.com.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 63671
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;hosted-by.myinternetservices.com. IN A
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Oct 17 10:15:02 CEST 2018
;; MSG SIZE rcvd: 61
But very often I want to have a shorter output from dig and I use the option +noall to achieve this:
ubuntu:~$ dig +noall +answer www.seznam.cz.
www.seznam.cz. 266 IN A 77.75.77.39
ubuntu:~$ dig +noall +short www.seznam.cz.
77.75.77.39
I also need to see the status for cases when there is no answer but I was not able to get the status when I use +noall. Is there a simple way how to show the status?
已采纳解答
原帖链接 · Andrew B · CC BY-SA 4.0
There is, but it makes the output less terse. The response code is only shown in +comments to the best of my knowledge.
$ dig +noall +comments +answer example.com
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7367
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; ANSWER SECTION:
example.com. 58368 IN A 93.184.216.34
The only way to condense it down any further is to perform your own text transformations on the above output. If you find yourself needing to work with the individual fields of a DNS response frequently, you might be better off looking at writing a custom script using a DNS client library for your preferred language.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
