示例#1
0
 /**
  * Discover host and port for specified prefix and ports
  *
  * @param $email
  * @param $prefix
  * @param $ports
  * @return array
  * @throws \Exception
  */
 private function analyse($email, $prefix, $ports)
 {
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         throw new \Exception('Not a valid email');
     }
     $host = null;
     $domain = explode('@', $email);
     if ($mxServer = Dns::getTopMx($domain[1])) {
         // save MX-server information
         $mxServerDomains = explode('.', $mxServer);
         $mxServerRoot = implode('.', array_slice($mxServerDomains, -2, 2));
         $this->mxServer = $mxServer;
         $this->mxServerRoot = $mxServerRoot;
     }
     if ($port = Socket::pingPort($prefix . $domain[1], $ports)) {
         $host = $prefix . $domain[1];
     } elseif ($mxServer) {
         if ($port = Socket::pingPort($mxServer, $ports)) {
             $host = $mxServer;
         } else {
             $revMxServer = gethostbyaddr(gethostbyname($mxServer));
             $revMxServerDomains = explode('.', $revMxServer);
             $revMxServerRoot = @implode('.', array_slice($revMxServerDomains, -2, 2));
             if ($port = Socket::pingPort($prefix . $revMxServerRoot, $ports)) {
                 $host = $prefix . $revMxServerRoot;
             } else {
                 if ($port = Socket::pingPort($prefix . $mxServerRoot, $ports)) {
                     $host = $prefix . $mxServerRoot;
                 }
             }
         }
     }
     return [$host, $port];
 }