嗨,老铁,欢迎来到我的博客!

如果觉得我的内容还不错的话,可以关注下我在 segmentfault.com 上的直播。我主要从事 PHP 和 Java 方面的开发,《深入 PHP 内核》作者之一。

[视频直播] PHP 进阶之路 - 亿级 pv 网站架构的技术细节与套路 直播中我将毫无保留的分享我这六年的全部工作经验和踩坑的故事,以及会穿插着一些面试中的 考点难点加分点

周梦康 发表于 2014-04-12 2913 次浏览 标签 : PHP翻译

由于对DNS这块基本是空白,翻译的好困难,而且翻译得肯定不是很准确吧。真怕上线了被喷。

hostname should be a valid DNS hostname such as "www.example.com". Reverse lookups can be generated using in-addr.arpa notation, but gethostbyaddr() is more suitable for the majority of reverse lookups.

主机名应该是一个DNS解析生效的域名,例如“www.example.com”。主机名也可以是通过对逆向解析域做DNS逆向域名解析而得到,但是在大多数情况下,gethostbyaddr()更加适合做逆向域名解析。

reverse lookup+ in-addr.arpa的参考资料:http://www.dns110.com/faq/html/2009101210725-1.Html


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 mail().

每个DNS标准,邮件地址必须是user.host这样的格式(例如hostmaster.example.com而不是hostmaster@example.com),在使用mail()这个函数之前请检查这个值,有必要的话还需要修改。


By default, dns_get_record() will search for any resource records associated with hostname. To limit the query, specify the optional type parameter. May be any one of the following: 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.

默认情况下,dns_get_record将会搜索所有与hostname相关的记录,可以通过设置type来限定查询。type的值可以是下面的其中的任何一个: 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或者DNS_ANY。


Because of eccentricities in the performance of libresolv between platforms, DNS_ANY will not always return every record, the slower DNS_ALL will collect all records more reliably.

由于dns在各个平台上表现有些不一样,DNS_ANY不会总是返回所有的记录,DNS_ALL虽然慢一些,但是会得到所有的记录,所以使用DNS_ALL更加可靠些。

Passed by reference and, if given, will be populated with Resource Records for the Authoritative Name Servers.

以引用方式传递,如果写了该参数,那么将会得到该解析记录的DNS服务器的信息。


Passed by reference and, if given, will be populated with any Additional Records.

以引用方式传递,如果填写了该参数,将会得到其他所有的DNS解析记录。


In case of raw mode, we query only the requestd type instead of looping type by type before going with the additional info stuff.

在原生模式下,在进行额外的查询的时候之前我们只执行请求的DNS类型,而不是循环查询所有的类型。


This function returns an array of associative arrays, or FALSE on failure. Each associative array contains at minimum the following keys:

这个函数返回一个关联数组,如果失败则返回FALSE。每个关联数组都至少包含了以下的这些键。

真是坑爹,又丢失,只能再编辑一次咯。

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 330268 $ -->
<!-- EN-Revision: 330268 Maintainer: zhoumengkang Status: ready -->
<refentry xml:id="function.dns-get-record" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>dns_get_record</refname>
  <refpurpose>获取指定主机的DNS记录</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>array</type><methodname>dns_get_record</methodname>
   <methodparam><type>string</type><parameter>hostname</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer>DNS_ANY</initializer></methodparam>
   <methodparam choice="opt"><type>array</type><parameter role="reference">authns</parameter></methodparam>
   <methodparam choice="opt"><type>array</type><parameter role="reference">addtl</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter role="reference">raw</parameter><initializer>false</initializer></methodparam>
  </methodsynopsis>
  <para>
   获取指定主机(<parameter>hostname</parameter>)的DNS记录。
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>hostname</parameter></term>
     <listitem>
      <para>
       主机名(<parameter>hostname</parameter>)应该是一个DNS解析生效的域名,例如“<literal>www.example.com</literal>”。主机名也可以是通过对逆向解析域做DNS逆向域名解析而得到,但是在大多数情况下<function>gethostbyaddr</function>更加适合做逆向域名解析。
      </para>
      <note>
       <para>
        每个DNS标准,邮件地址必须是<literal>user.host</literal>这样的格式(例如<literal>hostmaster.example.com</literal>而不是<literal>hostmaster@example.com</literal>),在使用<function>mail</function>这个函数之前请检查这个值,有必要的话还需要修改。
       </para>
      </note>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>type</parameter></term>
     <listitem>
      <para>
       默认情况下,<function>dns_get_record</function>将会搜索所有与<parameter>hostname</parameter>相关的记录,可以通过设置<parameter>type</parameter>来限定查询。<parameter>type</parameter>的值可以是下面的其中的任何一个: <constant>DNS_A</constant>,<constant>DNS_CNAME</constant>,<constant>DNS_HINFO</constant>,<constant>DNS_MX</constant>,<constant>DNS_NS</constant>,<constant>DNS_PTR</constant>,<constant>DNS_SOA</constant>,<constant>DNS_TXT</constant>,<constant>DNS_AAAA</constant>,<constant>DNS_SRV</constant>,<constant>DNS_NAPTR</constant>,<constant>DNS_A6</constant>,<constant>DNS_ALL</constant>或者<constant>DNS_ANY</constant>。
      </para>
      <note>
       <para>
        由于dns在各个平台上表现有些不一样,<constant>DNS_ANY</constant>不会总是返回所有的记录,<constant>DNS_ALL</constant>虽然慢一些,但是会得到所有的记录,所以使用DNS_ALL更加可靠些。
       </para>
      </note>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>authns</parameter></term>
     <listitem>
      <para>
       以引用方式传递,如果写了该参数,那么将会得到该解析记录的DNS服务器(<emphasis>Authoritative Name Servers</emphasis>)的信息。
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>addtl</parameter></term>
     <listitem>
      <para>
       以引用方式传递,如果填写了该参数,将会得到其他所有的DNS解析记录。
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>raw</parameter></term>
     <listitem>
      <para>
       在原生模式下,在进行额外的查询的时候之前我们只执行请求的DNS类型,而不是循环查询所有的类型。
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   这个函数返回一个关联数组,如果失败则 &return.falseforfailure;。每个关联数组都至少包含了以下的这些键。
   <emphasis>at minimum</emphasis> the following keys:
   <table>
    <title>Basic DNS attributes</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>Attribute</entry>
       <entry>Meaning</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>host</entry>
       <entry>
        The record in the DNS namespace to which the rest of the associated data refers.
       </entry>
      </row>
      <row>
       <entry>class</entry>
       <entry>
        <function>dns_get_record</function> only returns Internet class records and as
        such this parameter will always return <literal>IN</literal>.
       </entry>
      </row>
      <row>
       <entry>type</entry>
       <entry>
        String containing the record type.  Additional attributes will also be contained
        in the resulting array dependant on the value of type. See table below.
       </entry>
      </row>
      <row>
       <entry>ttl</entry>
       <entry>
        <literal>"Time To Live"</literal> remaining for this record. This will <emphasis>not</emphasis> 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.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
  <para>
   <table>
    <title>Other keys in associative arrays dependant on 'type'</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>Type</entry>
       <entry>Extra Columns</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry><literal>A</literal></entry>
       <entry>
        <literal>ip</literal>: An IPv4 addresses in dotted decimal notation.
       </entry>
      </row>
      <row>
       <entry><literal>MX</literal></entry>
       <entry>
        <literal>pri</literal>: Priority of mail exchanger.
        Lower numbers indicate greater priority.
        <literal>target</literal>: FQDN of the mail exchanger.
        See also <function>dns_get_mx</function>.
       </entry>
      </row>
      <row>
       <entry><literal>CNAME</literal></entry>
       <entry>
        <literal>target</literal>: FQDN of location in DNS namespace to which
        the record is aliased.
       </entry>
      </row>
      <row>
       <entry><literal>NS</literal></entry>
       <entry>
        <literal>target</literal>: FQDN of the name server which is authoritative
        for this hostname.
       </entry>
      </row>
      <row>
       <entry><literal>PTR</literal></entry>
       <entry>
        <literal>target</literal>: Location within the DNS namespace to which
        this record points.
       </entry>
      </row>
       <row>
       <entry><literal>TXT</literal></entry>
       <entry>
        <literal>txt</literal>: Arbitrary string data associated with this record.
       </entry>
      </row>
      <row>
       <entry><literal>HINFO</literal></entry>
       <entry>
        <literal>cpu</literal>: IANA number designating the CPU of the machine
        referenced by this record.
        <literal>os</literal>: IANA number designating the Operating System on
        the machine referenced by this record.
        See IANA's <link xlink:href="&url.iana.system-names;"><literal>Operating System
        Names</literal></link> for the meaning of these values.
       </entry>
      </row>
      <row>
       <entry><literal>SOA</literal></entry>
       <entry>
        <literal>mname</literal>: FQDN of the machine from which the resource
        records originated.
        <literal>rname</literal>: Email address of the administrative contain
        for this domain.
        <literal>serial</literal>: Serial # of this revision of the requested
        domain.
        <literal>refresh</literal>: Refresh interval (seconds) secondary name
        servers should use when updating remote copies of this domain.
        <literal>retry</literal>: Length of time (seconds) to wait after a
        failed refresh before making a second attempt.
        <literal>expire</literal>: Maximum length of time (seconds) a secondary
        DNS server should retain remote copies of the zone data without a
        successful refresh before discarding.
        <literal>minimum-ttl</literal>: 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.
       </entry>
      </row>
      <row>
       <entry><literal>AAAA</literal></entry>
       <entry>
        <literal>ipv6</literal>: IPv6 address
       </entry>
      </row>
      <row>
       <entry><literal>A6</literal>(PHP &gt;= 5.1.0)</entry>
       <entry>
        <literal>masklen</literal>: Length (in bits) to inherit from the target
        specified by <parameter>chain</parameter>.
        <literal>ipv6</literal>: Address for this specific record to merge with
        <parameter>chain</parameter>.
        <literal>chain</literal>: Parent record to merge with
        <parameter>ipv6</parameter> data.
       </entry>
      </row>
      <row>
       <entry><literal>SRV</literal></entry>
       <entry>
        <literal>pri</literal>: (Priority) lowest priorities should be used first.
        <literal>weight</literal>: Ranking to weight which of commonly prioritized
        <parameter>targets</parameter> should be chosen at random.
        <literal>target</literal> and <literal>port</literal>: hostname and port
        where the requested service can be found.
        For additional information see: <link xlink:href="&url.rfc;2782">RFC 2782</link>
       </entry>
      </row>
      <row>
       <entry><literal>NAPTR</literal></entry>
       <entry>
        <literal>order</literal> and <literal>pref</literal>: Equivalent to
        <parameter>pri</parameter> and <parameter>weight</parameter> above.
        <literal>flags</literal>, <literal>services</literal>, <literal>regex</literal>,
        and <literal>replacement</literal>: Parameters as defined by
        <link xlink:href="&url.rfc;2915">RFC 2915</link>.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>5.4.0</entry>
       <entry>
        增加了参数<parameter>raw</parameter>。
       </entry>
      </row>
      <row>
       <entry>5.3.0</entry>
       <entry>
         可以是在windows平台上使用这个函数了。
       </entry>
      </row>
      <row>
       <entry>5.3.0</entry>
       <entry>
        在此版本之前,如果给参数<parameter>authns</parameter>传入值,则必须同时传入<parameter>addtl</parameter>的值。
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>使用 <function>dns_get_record</function>函数</title>
    <programlisting role="php">
<![CDATA[
<?php
$result = dns_get_record("php.net");
print_r($result);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
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
        )

)
]]>
    </screen>
   </example>
   <example>
    <title>使用<function>dns_get_record</function>配合DNS_ANY的例子</title>
    <para>
     由于我们经常会想获取一个邮件服务器的对应的IP地址的MX记录是否已经生效。在使用<function>dns_get_record</function>函数之后,<parameter>addtl</parameter>能够返回一个相关的数组记录,<parameter>authns</parameter>参数则会返回授权服务器的列表信息。
    </para>
    <programlisting role="php">
<![CDATA[
<?php
/* Request "ANY" record for php.net,
   and create $authns and $addtl arrays
   containing list of name servers and
   any additional records which go with
   them */
$result = dns_get_record("php.net", DNS_ANY, $authns, $addtl);
echo "Result = ";
print_r($result);
echo "Auth NS = ";
print_r($authns);
echo "Additional = ";
print_r($addtl);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
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
        )

)
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    For compatibility with versions before PHP 5.3.0 on some operating systems,
    try the <link xlink:href="&url.php.pear;">PEAR</link> class
    <link xlink:href="&url.pear.package;Net_DNS">Net_DNS</link>.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>dns_get_mx</function></member>
    <member><function>dns_check_record</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

嗨,老铁,欢迎来到我的博客!

如果觉得我的内容还不错的话,可以关注下我在 segmentfault.com 上的直播。我主要从事 PHP 和 Java 方面的开发,《深入 PHP 内核》作者之一。

[视频直播] PHP 进阶之路 - 亿级 pv 网站架构的技术细节与套路 直播中我将毫无保留的分享我这六年的全部工作经验和踩坑的故事,以及会穿插着一些面试中的 考点难点加分点

评论列表