Esempio n. 1
0
 /**
  * Lookup an IP address (ipv4 and ipv6) and domain names
  * 
  * @throws NoQueryException
  * @throws instance of AbstractException if throwExceptions = true
  * @param  string $query
  * @return object
  */
 public function lookup($query = '')
 {
     $this->Result = new Result();
     $this->Config = new Config($this->specialWhois, $this->customConfigFile);
     try {
         if ($query == '') {
             throw new NoQueryException('No lookup query given');
         }
         $this->prepare($query);
         if (isset($this->Query->ip)) {
             $config = $this->Config->get('iana');
         } else {
             if (isset($this->Query->tldGroup)) {
                 $config = $this->Config->get($this->Query->tldGroup, $this->Query->idnTld);
             } else {
                 $config = $this->Config->get($this->Query->asn);
             }
             if ($config['server'] == '' || $this->Query->domain == '') {
                 $config = $this->Config->get('iana');
             }
         }
         $this->Config->setCurrent($config);
         $this->call();
     } catch (AbstractException $e) {
         if ($this->throwExceptions) {
             throw $e;
         }
         $this->Result->addItem('exception', $e->getMessage());
         $this->Result->addItem('rawdata', $this->rawdata);
         if (isset($this->Query)) {
             if (isset($this->Query->ip)) {
                 $this->Result->addItem('name', $this->Query->ip);
             } else {
                 $this->Result->addItem('name', $this->Query->fqdn);
             }
         } else {
             $this->Result->addItem('name', $query);
         }
     }
     // call cleanUp method
     $this->Result->cleanUp($this->Config->getCurrent(), $this->dateformat);
     // peparing output of Result by format
     switch ($this->format) {
         case 'json':
             return $this->Result->toJson();
             break;
         case 'serialize':
             return $this->Result->serialize();
             break;
         case 'array':
             return $this->Result->toArray();
             break;
         case 'xml':
             return $this->Result->toXml();
             break;
         default:
             return $this->Result;
     }
 }