function parse($data, $query)
 {
     $result['regrinfo'] = array();
     $result['regyinfo'] = array();
     $result['regyinfo']['registrar'] = 'American Registry for Internet Numbers (ARIN)';
     $result['rawdata'] = array();
     if (!$this->deep_whois) {
         return null;
     }
     $this->Query = array();
     $this->Query['server'] = 'whois.arin.net';
     $this->Query['query'] = $query;
     reset($this->REGISTRARS);
     $rawdata = $data['rawdata'];
     if (empty($rawdata)) {
         return $result;
     }
     $orgname = trim($rawdata[0]);
     if ($orgname == '') {
         $orgname = trim($rawdata[1]);
     }
     while (list($string, $whois) = each($this->REGISTRARS)) {
         if (strstr($orgname, $string) != '') {
             $this->Query['server'] = $whois;
             $result['regyinfo']['registrar'] = $string;
             break;
         }
     }
     // More queries to get more accurated data
     $more_data = array();
     switch ($this->Query['server']) {
         case 'whois.apnic.net':
             $rawdata = $this->GetRawData($query);
             if (empty($rawdata)) {
                 break;
             }
             while (list($ln, $line) = each($rawdata)) {
                 if (strstr($line, 'KRNIC whois server at whois.krnic.net') || strstr($line, 'KRNIC-KR')) {
                     $result = $this->set_whois_info($result);
                     $this->Query['server'] = 'whois.krnic.net';
                     $result['regyinfo']['registrar'] = 'Korea Network Information Center (KRNIC)';
                     $rawdata = $this->GetRawData($query);
                     break;
                 }
             }
             break;
         case 'whois.arin.net':
             $newquery = '';
             while (list($ln, $line) = each($rawdata)) {
                 $s = strstr($line, '(NETBLK-');
                 if ($s == '') {
                     $s = strstr($line, '(NET-');
                 }
                 if ($s != '') {
                     $netname = substr(strtok($s, ') '), 1);
                     if ($newquery == '') {
                         $newquery = $netname;
                     } else {
                         $more_data[] = array('query' => '!' . $netname, 'server' => 'whois.arin.net', 'handler' => 'arin');
                     }
                 }
             }
             if ($newquery != '') {
                 //$result = $this->set_whois_info($result);
                 $result['regyinfo']['netname'] = $newquery;
                 if (strstr($newquery, 'BRAZIL-BLK')) {
                     $this->Query['server'] = 'whois.registro.br';
                     $result['regyinfo']['registrar'] = 'Comite Gestor da Internet no Brasil';
                     $rawdata = $this->GetRawData($query);
                     break;
                 }
                 $rawdata = $this->GetRawData('!' . $newquery);
             } else {
                 $rawdata = '';
             }
             break;
         case 'whois.lacnic.net':
             $rawdata = $this->GetRawData($query);
             if (empty($rawdata)) {
                 break;
             }
             while (list($ln, $line) = each($rawdata)) {
                 $s = strstr($line, 'at whois.registro.br or ');
                 if ($s == '') {
                     $s = strstr($line, 'Copyright registro.br');
                 }
                 if ($s == '') {
                     $s = strstr($line, 'Copyright (c) Nic.br');
                 }
                 if ($s != '') {
                     $result = $this->set_whois_info($result);
                     $this->Query['server'] = 'whois.registro.br';
                     $result['regyinfo']['registrar'] = 'Comite Gestor da Internet do Brazil';
                     $rawdata = $this->GetRawData($query);
                     break;
                 }
             }
             break;
         case 'whois.ripe.net':
             $rawdata = $this->GetRawData($query);
             if (empty($rawdata)) {
                 break;
             }
             while (list($ln, $line) = each($rawdata)) {
                 if (strstr($line, 'AFRINIC-NET-TRANSFERRED-')) {
                     $result = $this->set_whois_info($result);
                     $this->Query['server'] = 'whois.afrinic.net';
                     $result['regyinfo']['registrar'] = 'African Network Information Center';
                     $rawdata = $this->GetRawData($query);
                     break;
                 }
             }
             break;
         default:
             $rawdata = $this->GetRawData($query);
     }
     if (empty($rawdata)) {
         $rawdata = $data['rawdata'];
     } else {
         $result = $this->set_whois_info($result);
     }
     $result['rawdata'] = $rawdata;
     if (isset($this->HANDLERS[$this->Query['server']])) {
         $this->Query['handler'] = $this->HANDLERS[$this->Query['server']];
     }
     if (!empty($this->Query['handler'])) {
         $this->Query['file'] = sprintf('whois.ip.%s.php', $this->Query['handler']);
         $result['regrinfo'] = $this->Process($result['rawdata']);
     }
     // Arrange inetnum/cdir
     if (isset($result['regrinfo']['network']['inetnum']) && strpos($result['regrinfo']['network']['inetnum'], '/') != false) {
         //Convert CDIR to inetnum
         $result['regrinfo']['network']['cdir'] = $result['regrinfo']['network']['inetnum'];
         $result['regrinfo']['network']['inetnum'] = cidr_conv($result['regrinfo']['network']['cdir']);
     }
     if (!isset($result['regrinfo']['network']['inetnum']) && isset($result['regrinfo']['network']['cdir'])) {
         //Convert CDIR to inetnum
         $result['regrinfo']['network']['inetnum'] = cidr_conv($result['regrinfo']['network']['cdir']);
     }
     // Try to find abuse email address
     if (!isset($result['regrinfo']['abuse']['email'])) {
         reset($result['rawdata']);
         while (list($key, $line) = each($result['rawdata'])) {
             $email_regex = "/([-_\\w\\.]+)(@)([-_\\w\\.]+)\\b/i";
             if (strpos($line, 'abuse') !== false && preg_match($email_regex, $line, $matches) > 0) {
                 $result['regrinfo']['abuse']['email'] = $matches[0];
                 break;
             }
         }
     }
     //Check if Referral rwhois server has been reported
     if (isset($result['regrinfo']['rwhois'])) {
         $more_data[] = array('query' => $query, 'server' => $result['regrinfo']['rwhois'], 'handler' => 'rwhois');
         $result['regyinfo']['rwhois'] = $result['regrinfo']['rwhois'];
         unset($result['regrinfo']['rwhois']);
     }
     // more queries can be done to get more accurated data
     reset($more_data);
     while (list($key, $srv_data) = each($more_data)) {
         $this->Query['server'] = $srv_data['server'];
         unset($this->Query['handler']);
         $rwdata = $this->GetRawData($srv_data['query']);
         if (!empty($rwdata)) {
             // Merge rawdata results
             $result['rawdata'][] = '';
             foreach ($rwdata as $line) {
                 $result['rawdata'][] = $line;
             }
             $result = $this->set_whois_info($result);
             $this->Query['handler'] = $srv_data['handler'];
             $this->Query['file'] = 'whois.' . $this->Query['handler'] . '.php';
             $rwres = $this->Process($rwdata);
             if (isset($rwres['network'])) {
                 $result = $this->join_result($result, 'network', $rwres);
             }
             if (isset($rwres['owner'])) {
                 $result = $this->join_result($result, 'owner', $rwres);
             }
             if (isset($rwres['tech'])) {
                 $result = $this->join_result($result, 'tech', $rwres);
             }
             if (isset($rwres['abuse'])) {
                 $result = $this->join_result($result, 'abuse', $rwres);
             }
             if (isset($rwres['admin'])) {
                 $result = $this->join_result($result, 'admin', $rwres);
             }
             if (isset($rwres['rwhois'])) {
                 $more_data[] = array('query' => $query, 'server' => $rwres['rwhois'], 'handler' => 'rwhois');
                 unset($rwres['rwhois']);
             }
         }
     }
     // IP or AS ?
     if (isset($result['regrinfo']['AS'])) {
         $result['regyinfo']['type'] = 'AS';
     } else {
         $result['regyinfo']['type'] = 'ip';
     }
     return $result;
 }
示例#2
0
 function parse($data, $query)
 {
     $result['regrinfo'] = array();
     $result['regyinfo'] = array();
     $result['regyinfo']['registrar'] = 'American Registry for Internet Numbers (ARIN)';
     $result['rawdata'] = array();
     if (!$this->deep_whois) {
         return null;
     }
     $this->Query = array();
     $this->Query['server'] = 'whois.arin.net';
     $this->Query['string'] = $query;
     reset($this->REGISTRARS);
     $rawdata = $data['rawdata'];
     $orgname = trim($rawdata[0]);
     if ($orgname == '') {
         $orgname = trim($rawdata[1]);
     }
     while (list($string, $whois) = each($this->REGISTRARS)) {
         if (strstr($orgname, $string) != '') {
             $this->Query['server'] = $whois;
             $result['regyinfo']['registrar'] = $string;
             break;
         }
     }
     switch ($this->Query['server']) {
         case 'whois.apnic.net':
             $rawdata = $this->GetData($query);
             if (!isset($rawdata['rawdata'])) {
                 $rawdata = $data['rawdata'];
                 break;
             }
             $rawdata = $rawdata['rawdata'];
             while (list($ln, $line) = each($rawdata)) {
                 if (strstr($line, 'KRNIC whois server at whois.krnic.net') || strstr($line, 'KRNIC-KR')) {
                     $this->Query['server'] = 'whois.krnic.net';
                     $result['regyinfo']['registrar'] = 'Korea Network Information Center (KRNIC)';
                     $rawdata = $this->GetData($query);
                     $rawdata = $rawdata['rawdata'];
                     break;
                 }
             }
             break;
         case 'whois.arin.net':
             $newquery = '';
             while (list($ln, $line) = each($rawdata)) {
                 $s = strstr($line, '(NETBLK-');
                 if ($s != '') {
                     $newquery = substr(strtok($s, ') '), 1);
                     break;
                 }
                 $s = strstr($line, '(NET-');
                 if ($s != '') {
                     $newquery = substr(strtok($s, ') '), 1);
                     break;
                 }
             }
             if ($newquery != "") {
                 $result['regyinfo']['netname'] = $newquery;
             }
             if (strstr($newquery, 'BRAZIL-BLK')) {
                 $this->Query["server"] = 'whois.registro.br';
                 $result["regyinfo"]["registrar"] = 'Comite Gestor da Internet no Brasil';
                 $rawdata = $this->GetData($query);
                 $rawdata = $rawdata['rawdata'];
                 $newquery = '';
             }
             if ($newquery != '') {
                 $rawdata = $this->GetData('!' . $newquery);
                 $rawdata = $rawdata['rawdata'];
             }
             break;
         case 'whois.lacnic.net':
             $rawdata = $this->GetData($query);
             if (!isset($rawdata['rawdata'])) {
                 $rawdata = $data['rawdata'];
                 break;
             }
             $rawdata = $rawdata['rawdata'];
             while (list($ln, $line) = each($rawdata)) {
                 $s = strstr($line, 'at whois.registro.br or ');
                 if ($s == '') {
                     $s = strstr($line, 'Copyright registro.br');
                 }
                 if ($s != '') {
                     $this->Query['server'] = 'whois.registro.br';
                     $result['regyinfo']['registrar'] = 'Comite Gestor da Internet do Brazil';
                     $rawdata = $this->GetData($query);
                     $rawdata = $rawdata['rawdata'];
                     break;
                 }
             }
             break;
         case 'whois.ripe.net':
             $rawdata = $this->GetData($query);
             if (!isset($rawdata['rawdata'])) {
                 $rawdata = $data['rawdata'];
                 break;
             }
             $rawdata = $rawdata['rawdata'];
             while (list($ln, $line) = each($rawdata)) {
                 if (strstr($line, 'AFRINIC-NET-TRANSFERRED-')) {
                     $this->Query['server'] = 'whois.afrinic.net';
                     $result['regyinfo']['registrar'] = 'African Network Information Center';
                     $rawdata = $this->GetData($query);
                     $rawdata = $rawdata['rawdata'];
                     break;
                 }
             }
             break;
         default:
             $rawdata = $this->GetData($query);
             if (isset($rawdata['rawdata'])) {
                 $rawdata = $rawdata['rawdata'];
             } else {
                 $rawdata = $data['rawdata'];
             }
     }
     $result['rawdata'] = $rawdata;
     $result['regyinfo']['whois'] = $this->Query['server'];
     if (isset($this->HANDLERS[$this->Query['server']])) {
         $this->Query['handler'] = $this->HANDLERS[$this->Query['server']];
     }
     if (!empty($this->Query['handler'])) {
         $this->Query['file'] = sprintf('whois.ip.%s.php', $this->Query['handler']);
         $result['regrinfo'] = $this->Process($result['rawdata']);
     }
     // Arrange inetnum/cdir
     if (isset($result['regrinfo']['network']['inetnum']) && strpos($result['regrinfo']['network']['inetnum'], '/') != false) {
         //Convert CDIR to inetnum
         $result['regrinfo']['network']['cdir'] = $result['regrinfo']['network']['inetnum'];
         $result['regrinfo']['network']['inetnum'] = cidr_conv($result['regrinfo']['network']['cdir']);
     }
     if (!isset($result['regrinfo']['network']['inetnum']) && isset($result['regrinfo']['network']['cdir'])) {
         //Convert CDIR to inetnum
         $result['regrinfo']['network']['inetnum'] = cidr_conv($result['regrinfo']['network']['cdir']);
     }
     // Try to find abuse email address
     if (!isset($result['regrinfo']['abuse']['email'])) {
         reset($result['rawdata']);
         while (list($key, $line) = each($result['rawdata'])) {
             $email_regex = "/([-_\\w\\.]+)(@)([-_\\w\\.]+)\\b/i";
             if (strpos($line, 'abuse') !== false && preg_match($email_regex, $line, $matches) > 0) {
                 $result['regrinfo']['abuse']['email'] = $matches[0];
                 break;
             }
         }
     }
     //Check if Referral rwhois server has been reported
     if (isset($result['regrinfo']['rwhois'])) {
         $this->Query['server'] = $result['regrinfo']['rwhois'];
         unset($result['regrinfo']['rwhois']);
         //If so, get customer data from rwhois
         $this->Query['handler'] = 'rwhois';
         $this->Query['file'] = 'whois.rwhois.php';
         $rwdata = $this->GetData($query);
         if (!empty($rwdata)) {
             $result['rawdata'][] = '';
             $result['rawdata'] = array_merge($result['rawdata'], $rwdata['rawdata']);
             $rwres = $this->Process($rwdata);
             $result['regrinfo']['customer'] = $rwres;
             $result['regyinfo']['rwhois'] = $this->Query['server'];
         }
     }
     // IP or AS ?
     if (isset($result['regrinfo']['AS'])) {
         $result['regyinfo']['type'] = 'AS';
     } else {
         $result['regyinfo']['type'] = 'ip';
     }
     return $result;
 }