挖掘只显示答案

Zul*_*kis 68 dig

我只想 dig 来显示我的查询的答案。

通常,它会打印出很多这样的附加信息:

;; <<>> DiG 9.7.3 <<>> google.de
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55839
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.de.                     IN      A

;; ANSWER SECTION:
google.de.              208     IN      A       173.194.69.94

;; Query time: 0 msec
;; SERVER: 213.133.99.99#53(213.133.99.99)
;; WHEN: Sun Sep 23 10:02:34 2012
;; MSG SIZE  rcvd: 43
Run Code Online (Sandbox Code Playgroud)

我希望将其简化为答案部分。

dig 有很多选择,我发现一个很好的选择是 +noall +answer

; <<>> DiG 9.7.3 <<>> google.de +noall +answer
;; global options: +cmd
google.de.              145     IN      A       173.194.69.94
Run Code Online (Sandbox Code Playgroud)

它省略了大部分内容,但仍显示此选项。

关于如何使用 dig 选项删除它的任何想法?我当然可以使用其他工具将其剪掉,但是 dig 本身的选项将是最干净和最好的。

Cak*_*mox 73

我不确定您为什么在输出中收到评论。这是您想要的行为的正确选项集。以下是相同版本的 dig 的相同选项:

$ dig -version
DiG 9.7.3
$ dig +noall +answer google.de
google.de.      55  IN  A   173.194.44.216
google.de.      55  IN  A   173.194.44.223
google.de.      55  IN  A   173.194.44.215
$
Run Code Online (Sandbox Code Playgroud)

  • 这似乎很有趣。使用`dig +noall +answer google.de` 有效,`dig google.de +noall +answer` 无效,即使根据手册支持它。 (15认同)
  • 标志的顺序显然很重要。 (7认同)

Alp*_*tte 42

使用“+short”选项

[root@myhost ~]# dig +short google.com
216.58.194.142

[root@myhost ~]# dig +short -x 216.58.194.142
dfw06s49-in-f14.1e100.net.
dfw06s49-in-f142.1e100.net.

[root@myhost ~]# dig +short google.com soa
ns1.google.com. dns-admin.google.com. 181803313 900 900 1800 60
Run Code Online (Sandbox Code Playgroud)

  • 我想我对原始提问者的意图做了一个假设。对我来说,完整的答案行不太有用。如果我不记得 dig 的选项,我可以执行“dig google.com|grep ^google”。但是 +short 选项返回一个没有附加文本的 IP 地址或主机名,我可以(例如)在脚本中使用它来创建防火墙规则。这通常是 dig 输出中对我很重要的部分。使用“+noall +noanswer”选项,如果我想在脚本中使用结果,我仍然必须应用一些字符串处理。 (8认同)
  • 我仍然不明白,为什么以及如何这是这个问题的答案? (2认同)

Now*_*ker 8

使用dig +param domain,不是dig domain +param

% dig +noall +answer -t aaaa d.ns.zerigo.net
d.ns.zerigo.net.        37788   IN      AAAA    2607:fc88:1001:1::4
% dig -t aaaa d.ns.zerigo.net +noall +answer

; <<>> DiG 9.9.2-P2 <<>> -t aaaa d.ns.zerigo.net +noall +answer
;; global options: +cmd
d.ns.zerigo.net.        37797   IN      AAAA    2607:fc88:1001:1::4
Run Code Online (Sandbox Code Playgroud)

+noall +answerswitch 的工作方式因它在命令行中的位置而异。这肯定是一个错误,dig因为+short双方都可以正常工作。

% dig +short -t aaaa d.ns.zerigo.net
2607:fc88:1001:1::4

% dig -t aaaa d.ns.zerigo.net +short
2607:fc88:1001:1::4
Run Code Online (Sandbox Code Playgroud)

  • 接受的答案说“我不确定为什么你会在输出中收到评论。”,而我确实知道为什么,并且这个答案是最准确的。 (2认同)