Exemplo n.º 1
0
Arquivo: Whois.php Projeto: roojs/pear
 /**
  * Connects to the whois server and retrieves domain information
  *
  * @param string $nicServer FQDN of whois server to query
  * @param string $domain    Domain name to query
  *
  * @access private
  * @return mixed returns a PEAR_Error on failure, string of whois data on success
  */
 function _connect($nicServer, $domain)
 {
     include_once 'Net/Socket.php';
     if (is_null($nicServer) || empty($nicServer)) {
         return new PEAR_Error($this->_errorCodes[014], 14);
     }
     if (PEAR::isError($socket = new Net_Socket())) {
         return new PEAR_Error($this->_errorCodes[010], 10);
     }
     $result = $socket->connect($nicServer, $this->getPort(), null, $this->getTimeout(), $this->getOptions());
     if (PEAR::isError($result)) {
         return new PEAR_Error($this->_errorCodes[011], 11);
     }
     $socket->setBlocking(false);
     // Querying denic.de requires some special coaxing for a domain query.
     // http://www.denic.de/en/faq-single/2978/1115.html
     if (substr($domain, -3) == '.de') {
         if (PEAR::isError($socket->writeLine("-T dn,ace " . $domain))) {
             return new PEAR_Error($this->_errorCodes[012], 12);
         }
     } else {
         if (PEAR::isError($socket->writeLine($domain))) {
             return new PEAR_Error($this->_errorCodes[012], 12);
         }
     }
     $nHost = null;
     $whoisData = $socket->readAll();
     if (PEAR::isError($whoisData)) {
         return new PEAR_Error($this->_errorCodes[013], 13);
     }
     $data = explode("\n", $whoisData);
     foreach ($data as $line) {
         $line = rtrim($line);
         // check for whois server redirection
         if (!isset($nHost)) {
             $pattern = '/' . $this->_whoisServerID . '([a-z0-9.]+)\\n/i';
             if (preg_match($pattern, $line, $matches)) {
                 $nHost = $matches[1];
             } elseif ($nicServer == $this->_nicServers['ANICHOST']) {
                 foreach ($this->_ipNicServers as $ipNicServer) {
                     $server = trim($this->_nicServers[$ipNicServer], '.');
                     if (strstr($line, $server)) {
                         $nHost = $this->_nicServers[$ipNicServer];
                     }
                 }
             }
         }
     }
     // this should fail, but we'll call it anyway and ignore the error
     $socket->disconnect();
     if ($nHost && $nHost != $nicServer) {
         $tmpBuffer = $this->_connect($nHost, $domain);
         if (PEAR::isError($tmpBuffer)) {
             return $tmpBuffer;
         }
         $whoisData .= $tmpBuffer;
     }
     return $whoisData;
 }
Exemplo n.º 2
0
 /**
  * Connects to the whois server and retrieves domain information
  *
  * @param $nicServer string FQDN of whois server to query
  * @param $domain string domain name to query
  * @access private
  * @return mixed returns a PEAR_Error on failure, string of whois data on success
  */
 function _connect($nicServer, $domain)
 {
     include_once 'Net/Socket.php';
     if (PEAR::isError($socket = new Net_Socket())) {
         return new PEAR_Error($this->_errorCodes[010]);
     }
     if (PEAR::isError($socket->connect($nicServer, getservbyname('whois', 'tcp')))) {
         return new PEAR_Error($this->_errorCodes[011]);
     }
     $socket->setBlocking(false);
     if (PEAR::isError($socket->writeLine($domain))) {
         return new PEAR_Error($this->_errorCodes[012]);
     }
     $nHost = null;
     $whoisData = $socket->readAll();
     if (PEAR::isError($whoisData)) {
         return new PEAR_Error($this->_errorCodes[013]);
     }
     $data = explode("\n", $whoisData);
     foreach ($data as $line) {
         $line = rtrim($line);
         // check for whois server redirection
         if (!isset($nHost)) {
             if (preg_match("/" . $this->_whoisServerID . "(.*)/", $line, $matches)) {
                 $nHost = $matches[1];
             } elseif ($nicServer == $this->_nicServers["ANICHOST"]) {
                 foreach ($this->_ipNicServers as $ipNicServer) {
                     if (strstr($line, $ipNicServer)) {
                         $nHost = $ipNicServer;
                     }
                 }
             }
         }
     }
     // this should fail, but we'll call it anyway and ignore the error
     $socket->disconnect();
     if ($nHost) {
         $tmpBuffer = $this->_connect($nHost, $domain);
         if (PEAR::isError($tmpBuffer)) {
             return $tmpBuffer;
         }
         $whoisData .= $tmpBuffer;
     }
     return $whoisData;
 }