<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >dns_get_record</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Network Functions" HREF="ref.network.html"><LINK REL="PREVIOUS" TITLE="dns_get_mx" HREF="function.dns-get-mx.html"><LINK REL="NEXT" TITLE="fsockopen" HREF="function.fsockopen.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dns-get-mx.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.fsockopen.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.dns-get-record" ></A >dns_get_record</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN73865" ></A ><P > (PHP 5)</P >dns_get_record -- Fetch DNS Resource Records associated with a hostname </DIV ><DIV CLASS="refsect1" ><A NAME="AEN73868" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >dns_get_record</B > ( string hostname [, int type [, array &authns, array &addtl]])<BR ></BR ><P > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > This function is not implemented on Windows platforms. Try the <A HREF="http://pear.php.net/" TARGET="_top" >PEAR</A > class <A HREF="http://pear.php.net/package/Net_DNS" TARGET="_top" >Net_DNS</A >. </P ></BLOCKQUOTE ></DIV > </P ><P > This function returns an array of associative arrays. Each associative array contains <SPAN CLASS="emphasis" ><I CLASS="emphasis" >at minimum</I ></SPAN > the following keys: <DIV CLASS="table" ><A NAME="AEN73892" ></A ><P ><B >Tabel 1. Basic DNS attributes</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Attribute</TH ><TH >Meaning</TH ></TR ></THEAD ><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 > <B CLASS="function" >dns_get_record()</B > only returns Internet class records and as such this parameter will always return <VAR CLASS="literal" >IN</VAR >. </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 > Time To Live remaining for this record. This will <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > equal the record'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 ></DIV > </P ><P > <VAR CLASS="parameter" >hostname</VAR > should be a valid DNS hostname such as "www.example.com". Reverse lookups can be generated using in-addr.arpa notation, but <A HREF="function.gethostbyaddr.html" ><B CLASS="function" >gethostbyaddr()</B ></A > is more suitable for the majority of reverse lookups. </P ><P > By default, <B CLASS="function" >dns_get_record()</B > will search for any resource records associated with <VAR CLASS="parameter" >hostname</VAR >. To limit the query, specify the optional <VAR CLASS="parameter" >type</VAR > parameter. <VAR CLASS="parameter" >type</VAR > may be any one of the following: <TT CLASS="constant" ><B >DNS_A</B ></TT >, <TT CLASS="constant" ><B >DNS_CNAME</B ></TT >, <TT CLASS="constant" ><B >DNS_HINFO</B ></TT >, <TT CLASS="constant" ><B >DNS_MX</B ></TT >, <TT CLASS="constant" ><B >DNS_NS</B ></TT >, <TT CLASS="constant" ><B >DNS_PTR</B ></TT >, <TT CLASS="constant" ><B >DNS_SOA</B ></TT >, <TT CLASS="constant" ><B >DNS_TXT</B ></TT >, <TT CLASS="constant" ><B >DNS_AAAA</B ></TT >, <TT CLASS="constant" ><B >DNS_SRV</B ></TT >, <TT CLASS="constant" ><B >DNS_NAPTR</B ></TT >, <TT CLASS="constant" ><B >DNS_ALL</B ></TT > or <TT CLASS="constant" ><B >DNS_ANY</B ></TT >. The default is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >DNS_ANY</I ></SPAN >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > Because of eccentricities in the performance of libresolv between platforms, <TT CLASS="constant" ><B >DNS_ANY</B ></TT > will not always return every record, the slower <TT CLASS="constant" ><B >DNS_ALL</B ></TT > will collect all records more reliably. </P ></BLOCKQUOTE ></DIV > </P ><P > The optional third and fourth arguments to this function, <VAR CLASS="parameter" >authns</VAR > and <VAR CLASS="parameter" >addtl</VAR > are passed by reference and, if given, will be populated with Resource Records for the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Authoritative Name Servers</I ></SPAN >, and any <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Additional Records</I ></SPAN > respectively. See the example below. </P ><P > <DIV CLASS="table" ><A NAME="AEN73947" ></A ><P ><B >Tabel 2. Other keys in associative arrays dependant on 'type'</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Type</TH ><TH >Extra Columns</TH ></TR ></THEAD ><TBODY ><TR ><TD ><VAR CLASS="literal" >A</VAR ></TD ><TD > <VAR CLASS="literal" >ip</VAR >: An IPv4 addresses in dotted decimal notation. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >MX</VAR ></TD ><TD > <VAR CLASS="literal" >pri</VAR >: Priority of mail exchanger. Lower numbers indicate greater priority. <VAR CLASS="literal" >target</VAR >: FQDN of the mail exchanger. See also <A HREF="function.dns-get-mx.html" ><B CLASS="function" >dns_get_mx()</B ></A >. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >CNAME</VAR ></TD ><TD > <VAR CLASS="literal" >target</VAR >: FQDN of location in DNS namespace to which the record is aliased. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >NS</VAR ></TD ><TD > <VAR CLASS="literal" >target</VAR >: FQDN of the name server which is authoritative for this hostname. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >PTR</VAR ></TD ><TD > <VAR CLASS="literal" >target</VAR >: Location within the DNS namespace to which this record points. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >TXT</VAR ></TD ><TD > <VAR CLASS="literal" >txt</VAR >: Arbitrary string data associated with this record. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >HINFO</VAR ></TD ><TD > <VAR CLASS="literal" >cpu</VAR >: IANA number designating the CPU of the machine referenced by this record. <VAR CLASS="literal" >os</VAR >: IANA number designating the Operating System on the machine referenced by this record. See IANA's <A HREF="http://www.iana.org/assignments/operating-system-names" TARGET="_top" >Operating System Names</A > for the meaning of these values. </TD ></TR ><TR ><TD ><VAR CLASS="literal" >SOA</VAR ></TD ><TD > <VAR CLASS="literal" >mname</VAR >: FQDN of the machine from which the resource records originated. <VAR CLASS="literal" >rname</VAR >: Email address of the administrative contain for this domain. <VAR CLASS="literal" >serial</VAR >: Serial # of this revision of the requested domain. <VAR CLASS="literal" >refresh</VAR >: Refresh interval (seconds) secondary name servers should use when updating remote copies of this domain. <VAR CLASS="literal" >retry</VAR >: Length of time (seconds) to wait after a failed refresh before making a second attempt. <VAR CLASS="literal" >expire</VAR >: Maximum length of time (seconds) a secondary DNS server should retain remote copies of the zone data without a successful refresh before discarding. <VAR CLASS="literal" >minimum-ttl</VAR >: 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 ><VAR CLASS="literal" >AAAA</VAR ></TD ><TD > <VAR CLASS="literal" >ipv6</VAR >: IPv6 address </TD ></TR ><TR ><TD ><VAR CLASS="literal" >SRV</VAR ></TD ><TD > <VAR CLASS="literal" >pri</VAR >: (Priority) lowest priorities should be used first. <VAR CLASS="literal" >weight</VAR >: Ranking to weight which of commonly prioritized <VAR CLASS="parameter" >targets</VAR > should be chosen at random. <VAR CLASS="literal" >target</VAR > and <VAR CLASS="literal" >port</VAR >: hostname and port where the requested service can be found. For additional information see: <A HREF="http://www.faqs.org/rfcs/rfc2782" TARGET="_top" >RFC 2782</A > </TD ></TR ><TR ><TD ><VAR CLASS="literal" >NAPTR</VAR ></TD ><TD > <VAR CLASS="literal" >order</VAR > and <VAR CLASS="literal" >pref</VAR >: Equivalent to <VAR CLASS="parameter" >pri</VAR > and <VAR CLASS="parameter" >weight</VAR > above. <VAR CLASS="literal" >flags</VAR >, <VAR CLASS="literal" >services</VAR >, <VAR CLASS="literal" >regex</VAR >, and <VAR CLASS="literal" >replacement</VAR >: Parameters as defined by <A HREF="http://www.faqs.org/rfcs/rfc2915" TARGET="_top" >RFC 2915</A >. </TD ></TR ></TBODY ></TABLE ></DIV > </P ><P > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > Per DNS standards, email addresses are given in user.host format (for example: hostmaster.example.com as opposed to hostmaster@example.com), be sure to check this value and modify if necessary before using it with a functions such as <A HREF="function.mail.html" ><B CLASS="function" >mail()</B ></A >. </P ></BLOCKQUOTE ></DIV > </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN74037" ></A ><P ><B >Exemplu 1. Using <B CLASS="function" >dns_get_record()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$result </font><font color="#007700">= </font><font color="#0000BB">dns_get_record</font><font color="#007700">(</font><font color="#DD0000">"php.net"</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > Produces output similar to the following: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => Array ( [host] => php.net [type] => MX [pri] => 5 [target] => pair2.php.net [class] => IN [ttl] => 6765 ) [1] => Array ( [host] => php.net [type] => A [ip] => 64.246.30.37 [class] => IN [ttl] => 8125 ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > Since it's very common to want the IP address of a mail server once the MX record has been resolved, <B CLASS="function" >dns_get_record()</B > also returns an array in <VAR CLASS="parameter" >addtl</VAR > which contains associate records. <VAR CLASS="parameter" >authns</VAR > is returned as well containing a list of authoritative name servers. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN74047" ></A ><P ><B >Exemplu 2. Using <B CLASS="function" >dns_get_record()</B > and DNS_ANY</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font 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 /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">dns_get_record</font><font color="#007700">(</font><font color="#DD0000">"php.net"</font><font color="#007700">, </font><font color="#0000BB">DNS_ANY</font><font color="#007700">, </font><font color="#0000BB">$authns</font><font color="#007700">, </font><font color="#0000BB">$addtl</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Result = "</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Auth NS = "</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$authns</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Additional = "</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$addtl</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > Produces output similar to the following: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Result = Array ( [0] => Array ( [host] => php.net [type] => MX [pri] => 5 [target] => pair2.php.net [class] => IN [ttl] => 6765 ) [1] => Array ( [host] => php.net [type] => A [ip] => 64.246.30.37 [class] => IN [ttl] => 8125 ) ) Auth NS = Array ( [0] => Array ( [host] => php.net [type] => NS [target] => remote1.easydns.com [class] => IN [ttl] => 10722 ) [1] => Array ( [host] => php.net [type] => NS [target] => remote2.easydns.com [class] => IN [ttl] => 10722 ) [2] => Array ( [host] => php.net [type] => NS [target] => ns1.easydns.com [class] => IN [ttl] => 10722 ) [3] => Array ( [host] => php.net [type] => NS [target] => ns2.easydns.com [class] => IN [ttl] => 10722 ) ) Additional = Array ( [0] => Array ( [host] => pair2.php.net [type] => A [ip] => 216.92.131.5 [class] => IN [ttl] => 6766 ) [1] => Array ( [host] => remote1.easydns.com [type] => A [ip] => 64.39.29.212 [class] => IN [ttl] => 100384 ) [2] => Array ( [host] => remote2.easydns.com [type] => A [ip] => 212.100.224.80 [class] => IN [ttl] => 81241 ) [3] => Array ( [host] => ns1.easydns.com [type] => A [ip] => 216.220.40.243 [class] => IN [ttl] => 81241 ) [4] => Array ( [host] => ns2.easydns.com [type] => A [ip] => 216.220.40.244 [class] => IN [ttl] => 81241 ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="function.dns-get-mx.html" ><B CLASS="function" >dns_get_mx()</B ></A >, and <A HREF="function.dns-check-record.html" ><B CLASS="function" >dns_check_record()</B ></A > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.dns-get-mx.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.fsockopen.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dns_get_mx</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.network.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >fsockopen</TD ></TR ></TABLE ></DIV ></BODY ></HTML >