<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.network.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.dns-get-record.php',
    1 => 'dns_get_record',
    2 => 'Fetch DNS Resource Records associated with a hostname',
  ),
  'up' => 
  array (
    0 => 'ref.network.php',
    1 => 'Network Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.dns-get-mx.php',
    1 => 'dns_get_mx',
  ),
  'next' => 
  array (
    0 => 'function.fsockopen.php',
    1 => 'fsockopen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/network/functions/dns-get-record.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.dns-get-record" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dns_get_record</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">dns_get_record</span> &mdash; <span class="dc-title">Fetch DNS Resource Records associated with a hostname</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.dns-get-record-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>dns_get_record</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$hostname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code><span class="initializer"> = <strong><code>DNS_ANY</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$authoritative_name_servers</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$additional_records</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$raw</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Fetch DNS Resource Records associated with the given
   <code class="parameter">hostname</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.dns-get-record-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">hostname</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">hostname</code> should be a valid DNS hostname such
       as &quot;<code class="literal">www.example.com</code>&quot;. Reverse lookups can be generated
       using <code class="literal">in-addr.arpa</code> notation, but
       <span class="function"><a href="function.gethostbyaddr.php" class="function">gethostbyaddr()</a></span> is more suitable for
       the majority of reverse lookups.
      </p>
      <blockquote class="note"><p><strong class="note">Nota</strong>: 
       <p class="para">
        Per DNS standards, email addresses are given in <code class="literal">user.host</code> format (for
        example: <code class="literal">hostmaster.example.com</code> as opposed to <code class="literal">hostmaster@example.com</code>),
        be sure to check this value and modify if necessary before using it
        with a functions such as <span class="function"><a href="function.mail.php" class="function">mail()</a></span>.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">type</code></dt>
     <dd>
      <p class="para">
       By default, <span class="function"><strong>dns_get_record()</strong></span> will search for any
       resource records associated with <code class="parameter">hostname</code>. 
       To limit the query, use one of the
       <strong><code>DNS_<span class="replaceable">*</span></code></strong>
       constants.
      </p>
     </dd>
    
    
     <dt><code class="parameter">authoritative_name_servers</code></dt>
     <dd>
      <p class="para">
       Passed by reference and, if given, will be populated with Resource
       Records for the <em>Authoritative Name Servers</em>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">additional_records</code></dt>
     <dd>
      <p class="para">
       Passed by reference and, if given, will be populated with any
       <em>Additional Records</em>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">raw</code></dt>
     <dd>
      <p class="para">
       The <code class="parameter">type</code> will be interpreted as a raw DNS type ID
       (the <strong><code>DNS_<span class="replaceable">*</span></code></strong> constants cannot be used).
       The return value will contain a <code class="literal">data</code> key, which needs
       to be manually parsed.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.dns-get-record-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   This function returns an array of associative arrays,
    o <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento. Each associative array contains
   <em>at minimum</em> the following keys:
   <table class="doctable table">
    <caption><strong>Basic DNS attributes</strong></caption>
    
     <thead>
      <tr>
       <th>Attribute</th>
       <th>Meaning</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>host</td>
       <td>
        The record in the DNS namespace to which the rest of the associated data refers.
       </td>
      </tr>

      <tr>
       <td>class</td>
       <td>
        <span class="function"><strong>dns_get_record()</strong></span> only returns Internet class records and as
        such this parameter will always return <code class="literal">IN</code>.
       </td>
      </tr>

      <tr>
       <td>type</td>
       <td>
        String containing the record type.  Additional attributes will also be contained
        in the resulting array dependant on the value of type. See table below.
       </td>
      </tr>

      <tr>
       <td>ttl</td>
       <td>
        <code class="literal">&quot;Time To Live&quot;</code> remaining for this record. This will <em>not</em> equal
        the record&#039;s original ttl, but will rather equal the original ttl minus whatever
        length of time has passed since the authoritative name server was queried.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong>Other keys in associative arrays dependent on <code class="parameter">type</code></strong></caption>
    
     <thead>
      <tr>
       <th>Type</th>
       <th>Extra Columns</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">A</code></td>
       <td>
        <code class="literal">ip</code>: An IPv4 addresses in dotted decimal notation.
       </td>
      </tr>

      <tr>
       <td><code class="literal">MX</code></td>
       <td>
        <code class="literal">pri</code>: Priority of mail exchanger.
        Lower numbers indicate greater priority.
        <code class="literal">target</code>: FQDN of the mail exchanger.
        See also <span class="function"><a href="function.dns-get-mx.php" class="function">dns_get_mx()</a></span>.
       </td>
      </tr>

      <tr>
       <td><code class="literal">CNAME</code></td>
       <td>
        <code class="literal">target</code>: FQDN of location in DNS namespace to which
        the record is aliased.
       </td>
      </tr>

      <tr>
       <td><code class="literal">NS</code></td>
       <td>
        <code class="literal">target</code>: FQDN of the name server which is authoritative
        for this hostname.
       </td>
      </tr>

      <tr>
       <td><code class="literal">PTR</code></td>
       <td>
        <code class="literal">target</code>: Location within the DNS namespace to which
        this record points.
       </td>
      </tr>

       <tr>
       <td><code class="literal">TXT</code></td>
       <td>
        <code class="literal">txt</code>: Arbitrary string data associated with this record.
       </td>
      </tr>

      <tr>
       <td><code class="literal">HINFO</code></td>
       <td>
        <code class="literal">cpu</code>: IANA number designating the CPU of the machine
        referenced by this record.
        <code class="literal">os</code>: IANA number designating the Operating System on
        the machine referenced by this record.
        See IANA&#039;s <a href="http://www.iana.org/assignments/operating-system-names" class="link external">&raquo;&nbsp;<code class="literal">Operating System
        Names</code></a> for the meaning of these values.
       </td>
      </tr>

      <tr>
       <td><code class="literal">CAA</code></td>
       <td>
        <code class="literal">flags</code>: A one-byte bitfield; currently only bit 0 is defined,
        meaning &#039;critical&#039;; other bits are reserved and should be ignored.
        <code class="literal">tag</code>: The CAA tag name (alphanumeric ASCII string).
        <code class="literal">value</code>: The CAA tag value (binary string, may use subformats).
        For additional information see: <a href="https://datatracker.ietf.org/doc/html/rfc6844" class="link external">&raquo;&nbsp;RFC 6844</a>
       </td>
      </tr>

      <tr>
       <td><code class="literal">SOA</code></td>
       <td>
        <code class="literal">mname</code>: FQDN of the machine from which the resource
        records originated.
        <code class="literal">rname</code>: Email address of the administrative contact
        for this domain.
        <code class="literal">serial</code>: Serial # of this revision of the requested
        domain.
        <code class="literal">refresh</code>: Refresh interval (seconds) secondary name
        servers should use when updating remote copies of this domain.
        <code class="literal">retry</code>: Length of time (seconds) to wait after a
        failed refresh before making a second attempt.
        <code class="literal">expire</code>: Maximum length of time (seconds) a secondary
        DNS server should retain remote copies of the zone data without a
        successful refresh before discarding.
        <code class="literal">minimum-ttl</code>: Minimum length of time (seconds) a
        client can continue to use a DNS resolution before it should request
        a new resolution from the server.  Can be overridden by individual
        resource records.
       </td>
      </tr>

      <tr>
       <td><code class="literal">AAAA</code></td>
       <td>
        <code class="literal">ipv6</code>: IPv6 address
       </td>
      </tr>

      <tr>
       <td><code class="literal">A6</code></td>
       <td>
        <code class="literal">masklen</code>: Length (in bits) to inherit from the target
        specified by <code class="parameter">chain</code>.
        <code class="literal">ipv6</code>: Address for this specific record to merge with
        <code class="parameter">chain</code>.
        <code class="literal">chain</code>: Parent record to merge with
        <code class="parameter">ipv6</code> data.
       </td>
      </tr>

      <tr>
       <td><code class="literal">SRV</code></td>
       <td>
        <code class="literal">pri</code>: (Priority) lowest priorities should be used first.
        <code class="literal">weight</code>: Ranking to weight which of commonly prioritized
        <code class="parameter">targets</code> should be chosen at random.
        <code class="literal">target</code> and <code class="literal">port</code>: hostname and port
        where the requested service can be found.
        For additional information see: <a href="https://datatracker.ietf.org/doc/html/rfc2782" class="link external">&raquo;&nbsp;RFC 2782</a>
       </td>
      </tr>

      <tr>
       <td><code class="literal">NAPTR</code></td>
       <td>
        <code class="literal">order</code> and <code class="literal">pref</code>: Equivalent to
        <code class="parameter">pri</code> and <code class="parameter">weight</code> above.
        <code class="literal">flags</code>, <code class="literal">services</code>, <code class="literal">regex</code>,
        and <code class="literal">replacement</code>: Parameters as defined by
        <a href="https://datatracker.ietf.org/doc/html/rfc2915" class="link external">&raquo;&nbsp;RFC 2915</a>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.dns-get-record-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.0.16, 7.1.2</td>
       <td>
        Added support for CAA record type.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.dns-get-record-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Using <span class="function"><strong>dns_get_record()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$result </span><span style="color: #007700">= </span><span style="color: #0000BB">dns_get_record</span><span style="color: #007700">(</span><span style="color: #DD0000">"php.net"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; MX
            [pri] =&gt; 5
            [target] =&gt; pair2.php.net
            [class] =&gt; IN
            [ttl] =&gt; 6765
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; A
            [ip] =&gt; 64.246.30.37
            [class] =&gt; IN
            [ttl] =&gt; 8125
        )

)</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Using <span class="function"><strong>dns_get_record()</strong></span> and DNS_ANY</strong></p>
    <div class="example-contents"><p>
     Since it&#039;s very common to want the IP address of a mail server
     once the MX record has been resolved, <span class="function"><strong>dns_get_record()</strong></span>
     also returns an array in <code class="parameter">additional_records</code> which
     contains associate records.  <code class="parameter">authoritative_name_servers</code>
     is returned as well containing a list of authoritative name
     servers.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Request "ANY" record for php.net,<br />   and create $authns and $addtl arrays<br />   containing list of name servers and<br />   any additional records which go with<br />   them */<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">dns_get_record</span><span style="color: #007700">(</span><span style="color: #DD0000">"php.net"</span><span style="color: #007700">, </span><span style="color: #0000BB">DNS_ANY</span><span style="color: #007700">, </span><span style="color: #0000BB">$authns</span><span style="color: #007700">, </span><span style="color: #0000BB">$addtl</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Result = "</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Auth NS = "</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$authns</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Additional = "</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$addtl</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Result = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; MX
            [pri] =&gt; 5
            [target] =&gt; pair2.php.net
            [class] =&gt; IN
            [ttl] =&gt; 6765
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; A
            [ip] =&gt; 64.246.30.37
            [class] =&gt; IN
            [ttl] =&gt; 8125
        )

)
Auth NS = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; remote1.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; remote2.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [2] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; ns1.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [3] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; ns2.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

)
Additional = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; pair2.php.net
            [type] =&gt; A
            [ip] =&gt; 216.92.131.5
            [class] =&gt; IN
            [ttl] =&gt; 6766
        )

    [1] =&gt; Array
        (
            [host] =&gt; remote1.easydns.com
            [type] =&gt; A
            [ip] =&gt; 64.39.29.212
            [class] =&gt; IN
            [ttl] =&gt; 100384
        )

    [2] =&gt; Array
        (
            [host] =&gt; remote2.easydns.com
            [type] =&gt; A
            [ip] =&gt; 212.100.224.80
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

    [3] =&gt; Array
        (
            [host] =&gt; ns1.easydns.com
            [type] =&gt; A
            [ip] =&gt; 216.220.40.243
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

    [4] =&gt; Array
        (
            [host] =&gt; ns2.easydns.com
            [type] =&gt; A
            [ip] =&gt; 216.220.40.244
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.dns-get-record-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.dns-get-mx.php" class="function" rel="rdfs-seeAlso">dns_get_mx()</a> - Alias di getmxrr</span></li>
    <li><span class="function"><a href="function.dns-check-record.php" class="function" rel="rdfs-seeAlso">dns_check_record()</a> - Alias di checkdnsrr</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>