Hello,

I am after some help,

I need to know how to do srv lookups using php and possibly mx lookup,

I have a form which already has a textbox which selects the domian from a mysql database, I need to be able to display the srv record below the textbox, the srv record needs to start with _autodiscover._tcp.

I have looked online and you can use dns_get_record but can't seem to get in working for srv lookups

Can Anyone help

Cheers
Martin

Recommended Answers

All 4 Replies

You could use getmxrr():

<?php

    $url = 'daniweb.com';
    getmxrr($url, $matches, $weights);

    print_r($matches);
    print_r($weights);

Docs: http://php.net/getmxrr

Regarding dns_get_record() what kind of problem do you experience? Can you show your script?

I need to be able to display the srv record below the textbox, the srv record needs to start with _autodiscover._tcp.

Do you mean you want to filter and get only those with _autodiscover._tcp.? Here you can use strstr() or preg_match() or even preg_match_all() if the record contains more then one matching string.

Hi Cereal,

The code I am using is

<?php
$domain = strstr('_autodiscover._tcp.');

$result = dns_get_record("domain.com", DNS_SRV, $domain);
print_r($result);
?>

Thanks

Then you need something like this:

<?php

$url = 'domain.com';

$dnsquery = dns_get_record($url, DNS_SRV);
$records = array();
$match = '_autodiscover._tcp';

foreach($dnsquery as $key => $entry)
{
    if(strstr($entry['target'], $match) !== FALSE)
    {
        $records[] = $entry;
    }
}

print_r($records);

The $records variable will return an array of entries that match the string. If it does not work try with DNS_ALL.

Thanks,

Can't get it to work, just get an output of array() have tried both dns_all and dns_srv, gives me somthing to work on though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.