SRV record lookup with PHP
Asked Answered
B

2

3

If you type

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

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

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

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

Thanks!

Balzac answered 24/11, 2008 at 11:0 Comment(0)
E
8

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

Exterminatory answered 24/11, 2008 at 11:11 Comment(1)
I would rather privilege native PHP function over oldish PEAR libraries that doesn't play well with up-to-date PHP version. Answer of @Leopoldeen looks much better to me.Ling
L
9

There is dns_get_record(). According to the docs it can take an int $type argument, which refers to a set of constants, one of them being DNS_SRV.

Leopoldeen answered 24/11, 2008 at 11:13 Comment(0)
E
8

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

Exterminatory answered 24/11, 2008 at 11:11 Comment(1)
I would rather privilege native PHP function over oldish PEAR libraries that doesn't play well with up-to-date PHP version. Answer of @Leopoldeen looks much better to me.Ling

© 2022 - 2024 — McMap. All rights reserved.