PHP5:dns_get_record() 只返回子域的 A 记录

发布于 2024-08-02 08:57:05 字数 661 浏览 2 评论 0原文

在 Linux 上运行 PHP 5.2,我使用 dns_get_record() 运行一系列查询。从文档中可以看出,该函数复制了 dig 但我发现了不一致之处。我的目标是获得对每个主机名所属的域具有权威性的主要和辅助名称服务器。

dns_get_record('example.com', DNS_NS); 返回良好的结果。 dns_get_record('www.example.com', DNS_NS); 不返回任何内容。 dns_get_record('www.example.com', DNS_ANY); 仅返回 A 记录。 dns_get_record('www.example.com', DNS_SOA); 不返回任何内容。

但是,从使用 dig 的命令行,我总是可以至少获得 SOA:

dig www.example.com NS 或者 dig www.example.com SOA

返回包含名称服务器的有效权限部分(SOA 中)。

我怎样才能在 PHP 中复制这个?我尝试过 PEAR Net_DNS 模块,并看到与 dns_get_record() 类似的恶作剧。

Running PHP 5.2 on Linux, I am running a series of queries with dns_get_record(). It would appear from the documentation that this function replicates dig but I am seeing inconsistencies. My goal is to get the primary and secondary nameservers that are authoritative for the domains that each hostname belongs to.

dns_get_record('example.com', DNS_NS); returns good results.
dns_get_record('www.example.com', DNS_NS); returns nothing.
dns_get_record('www.example.com', DNS_ANY); returns only an A-record.
dns_get_record('www.example.com', DNS_SOA); returns nothing.

However, from a command line using dig, I can always get at least the SOA:

dig www.example.com NS
or
dig www.example.com SOA

return a valid AUTHORITY SECTION (IN SOA) containing the nameservers.

How can I replicate this in PHP? I have tried the PEAR Net_DNS module and seen similar shenanigans as with dns_get_record().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无边思念无边月 2024-08-09 08:57:05

当您从命令行dig时,您可以更直接(相对)地连接到 DNS。输出也针对该场景进行格式化。当执行 php 函数时,它返回其作者认为需要的值。不一定直接对应于dig

如果您想获得 dig 结果,则可以使用 exec('dig www.example.com ns'); 并根据需要解析返回输出。

另外,如果您正在查询 DNS 的子域,即 www.而不是 tld (example.com),那么您将不会得到与其关联的其他记录 - 您只会获得与该子域关联的结果,在您的情况下,这只是一个 A 记录。

When you dig from the command line you're much more directly (relatively) connecting to the DNS. The output is also formatted for that scenario. When executing the php function, it returns the values its authors thought would be wanted. Doesn't necessarily directly correspond to dig.

If you want to get a dig result then you could use exec('dig www.example.com ns'); and parse that return output as you want.

Also, if you're querying the DNS for a subdomain, i.e. www. rather than the tld (example.com), then you're not going to get the other records associated with it - you're ONLY going to get the results associated with that subdomain, which in your case is just an A record.

伪装你 2024-08-09 08:57:05

我遇到了类似的问题,对于节点(或子域),您需要更具体并了解您请求的 DNS 条目的文本。

例如,DMARC DNS 条目是 TXT 条目,SPF 和 DKIM 也是如此。

$showResult = dns_get_record('_dmarc.domain.com', DNS_TXT); //returns an array

工作正常。

I was having a similar issue, for the node (or subdomain) you need to be more specific and know the text of the DNS entry you are requesting.

e.g. a DMARC DNS entry is a TXT entry, as is SPF and DKIM.

$showResult = dns_get_record('_dmarc.domain.com', DNS_TXT); //returns an array

works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文