php MX Query - 结果不同

时间:2016-06-07 12:15:22

标签: php email records

我有一个旧的php4盒子,我试图利用它。 我没有nslookup,php getmxrr等。

我在php.net网站上找到了一个返回域名MX记录的函数。在这个例子中我使用gmail,但与getmxrr()相比,我获得了不同的结果。

getmxrr显示:

Array
(
    [0] => alt1.gmail-smtp-in.l.google.com
    [1] => alt3.gmail-smtp-in.l.google.com
    [2] => alt2.gmail-smtp-in.l.google.com
    [3] => gmail-smtp-in.l.google.com
    [4] => alt4.gmail-smtp-in.l.google.com
)

然后这个函数返回:

Array
(
    [0] => google.com
    [1] => alt3.google.com
    [2] => alt4.google.com
    [3] => alt2.google.com
    [4] => alt2.google.com.google.com
)

下面的代码显示了我如何调用getmxrr和函数,任何人都可以建议是否可以获得与getmxrr匹配的结果?它在端口53上查询相同的服务器。

<?php

getmxrr ( "gmail.com", $mxhosts);

echo "<pre>";
    print_r($mxhosts);
echo "</pre>";


class mxlookup
{
      var $dns_socket = NULL;
      var $QNAME = "";
      var $dns_packet= NULL;
      var $ANCOUNT = 0;
      var $cIx = 0;
      var $dns_repl_domain;
      var $arrMX = array();

      function mxlookup($domain, $dns="8.8.8.8")
      {
         $this->QNAME($domain);
         $this->pack_dns_packet();
         $dns_socket = fsockopen("udp://$dns", 53);

         fwrite($dns_socket,$this->dns_packet,strlen($this->dns_packet));
         $this->dns_reply  = fread($dns_socket,1);

         $bytes = stream_get_meta_data($dns_socket);
         $this->dns_reply .= fread($dns_socket,$bytes['unread_bytes']);
         fclose($dns_socket);
         $this->cIx=6;
         $this->ANCOUNT   = $this->gord(2);
         $this->cIx+=4;
         $this->parse_data($this->dns_repl_domain);
         $this->cIx+=7;

         for($ic=1;$ic<=$this->ANCOUNT;$ic++)
         {
           $QTYPE = ord($this->gdi($this->cIx));
           if($QTYPE!==15){print("[MX Record not returned]"); die();}
           $this->cIx+=9;
           $mxPref = ord($this->gdi($this->cIx));
           $this->parse_data($curmx);
           $this->arrMX[] = $curmx;
           $this->cIx+=3;
         }
      }

      function parse_data(&$retval)
      {
        $arName = array();
        $byte = ord($this->gdi($this->cIx));
        while($byte!==0)
        {
          if($byte==192) //compressed
          {
            $tmpIx = $this->cIx;
            $this->cIx = ord($this->gdi($cIx));
            $tmpName = $retval;
            $this->parse_data($tmpName);
            $retval=$retval.".".$tmpName;
            $this->cIx = $tmpIx+1;
            return;
          }
          $retval="";
          $bCount = $byte;
          for($b=0;$b<$bCount;$b++)
          {
            $retval .= $this->gdi($this->cIx);
          }
          $arName[]=$retval;
         $byte = ord($this->gdi($this->cIx));
       }
       $retval=join(".",$arName);
     }

     function gdi(&$cIx,$bytes=1)
     {
       $this->cIx++;
       return(substr($this->dns_reply, $this->cIx-1, $bytes));
     }

      function QNAME($domain)
      {
        $dot_pos = 0; $temp = "";
        while($dot_pos=strpos($domain,"."))
        {
          $temp   = substr($domain,0,$dot_pos);
          $domain = substr($domain,$dot_pos+1);
          $this->QNAME .= chr(strlen($temp)).$temp;
        }
        $this->QNAME .= chr(strlen($domain)).$domain.chr(0);
      }

      function gord($ln=1)
      {
        $reply="";
        for($i=0;$i<$ln;$i++){
         $reply.=ord(substr($this->dns_reply,$this->cIx,1));
         $this->cIx++;
         }

        return $reply;
      }

      function pack_dns_packet()
      {
        $this->dns_packet = chr(0).chr(1).
                            chr(1).chr(0).
                            chr(0).chr(1).
                            chr(0).chr(0).
                            chr(0).chr(0).
                            chr(0).chr(0).
                            $this->QNAME.
                            chr(0).chr(15).
                            chr(0).chr(1);
      }

}

/* Exampe of use: */
$mx = new mxlookup("gmail.com");

echo "<pre>";
    print_r($mx->arrMX);
echo "</pre>";
?>

由于

0 个答案:

没有答案