使用 PHP 查找 SRV 记录

2022-01-04 00:00:00 php dns srv

如果你输入

nslookup -type=SRV _xmpp-server._tcp.gmail.com

(或在 OSX 中使用 dig 命令)你会得到一些与谷歌聊天相关的 SRV 记录

(or use the dig command in OSX) you get some SRV records relating to google chat

我想在 PHP 中复制这个功能,有没有人有什么好的想法如何做到这一点?

I would like to replicate this functionality in PHP, does anyone have any good ideas how to do this?

我想避免使用 exec(),因为这不会在 OSX/*NIX/WINDOWS 中返回 100% 的标准响应

I would like to avoid using exec() as this does not return 100% standard responses across OSX/*NIX/WINDOWS

谢谢!

推荐答案

你可以使用 Pear Net_DNS.我设法让它在 Linux 上运行,但还没有在 Windows 或任何其他平台上测试过:

You could use Pear Net_DNS. I managed to get this to work on Linux, but haven't tested it on Windows or any others:

require_once('Net/DNS.php');
$resolver = new Net_DNS_Resolver();
$response = $resolver->query('_xmpp-server._tcp.gmail.com', 'SRV');
if ($response) {
    foreach ($response->answer as $rr) {
        $rr->display();
    }
}

我修改了他们文档中的示例.希望这有帮助

I modified the example from their documentation. hope this helps

相关文章