How to query DNS records using PHP

→ Are you a new visitor? Please visit the page guidance for new visitors ←

dns_get_record() function

This function actually gets us the actual DNS records data in a nice array that we can work with. The function also has a few parameters that we can use as before:

  • hostname – This would need to be a valid DNS hostname, for instance “google.com”. 
  • type – This is the type of query we want to make, for instance we have the following options:
    • DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY
  • authns – if used, this variable will be populated with Resource Records for the Authoritative Name Servers.
  • addtl – if used, this variable will be populate with any Additional Records
  • raw – if used, we query only the requested type instead of looping type by type before going with the additional info stuff.

In most application, I found this to be mostly used or the previous function, the first one provides you with a simple ‘yes’ or ‘no’ if a dns record exists and the dns_get_record() function will get you the actual data for the specific hostname.

Code example:

Output of this would be:

 ↠ Continue with getmxrr()

Pages: 1 2 3

Request an article ←