0

the code below used php functions to get me MX hostnames and their just ip version 4:

    $results = dns_get_record($domain, DNS_MX);

    foreach ($results as $res) {
        $hostip = gethostbyname($res['target']);
    }

i googled a lot about 'dig' and found "dig -t MX redhat.com +noall +answer" but it returns just the MX hostnames without their IPV4 and IPV6. Is there a way to get the job done using "dig" or PHP Functions?

Devilion
  • 74
  • 8

1 Answers1

1

The MX record contains only hostnames, never IP addresses.

If you want to look up the IP address of a hostname you received, you will need to perform another DNS lookup. It appears that your code is already doing this (and then throwing away some of the results, which is a bug). But unless you intend to do something with the IP address other than open a connection, then you should probably just use the hostname.

Community
  • 1
  • 1
Michael Hampton
  • 9,737
  • 4
  • 55
  • 96