function GetData($query = '', $deep_whois = true) { // If domain to query passed in, use it, otherwise use domain from initialisation $string = !empty($query) ? $query : $this->Query['string']; $this->Query['string'] = $string; // clear error description if (isset($this->Query['errstr'])) { unset($this->Query['errstr']); } if (!isset($this->Query['server'])) { $this->Query['status'] = -1; $this->Query['errstr'][] = 'No server specified'; return array(); } // Check if protocol is http if (substr($this->Query['server'], 0, 7) == 'http://' || substr($this->Query['server'], 0, 8) == 'https://') { $output = $this->httpQuery($this->Query['server']); $query_args = substr(strchr($this->Query['server'], '?'), 1); $this->Query['server'] = strtok($this->Query['server'], '?'); if (substr($this->Query['server'], 0, 7) == 'http://') { $this->Query['server_port'] = 80; } else { $this->Query['server_port'] = 483; } } else { // Get args if (strpos($this->Query['server'], '?')) { $parts = explode('?', $this->Query['server']); $this->Query['server'] = trim($parts[0]); $query_args = trim($parts[1]); // replace substitution parameters $query_args = str_replace('{query}', $string, $query_args); $query_args = str_replace('{version}', 'phpWhois' . $this->CODE_VERSION, $query_args); if (strpos($query_args, '{ip}') !== false) { $query_args = str_replace('{ip}', getclientip(), $query_args); } if (strpos($query_args, '{hname}') !== false) { $query_args = str_replace('{hname}', gethostbyaddr(getclientip()), $query_args); } } else { $query_args = $string; } if (substr($this->Query['server'], 0, 9) == 'rwhois://') { $this->Query['server'] = substr($this->Query['server'], 9); } // Get port if (strpos($this->Query['server'], ':')) { $parts = explode(':', $this->Query['server']); $this->Query['server'] = trim($parts[0]); $this->Query['server_port'] = trim($parts[1]); } else { $this->Query['server_port'] = $this->PORT; } // Connect to whois server, or return if failed $ptr = $this->Connect(); if ($ptr < 0) { $this->Query['status'] = -1; $this->Query['errstr'][] = 'Connect failed to: ' . $this->Query['server']; return array(); } if (version_compare(phpversion(), '4.3.0') >= 0) { stream_set_timeout($ptr, $this->STIMEOUT); } // Send query fputs($ptr, trim($query_args) . "\r\n"); // Prepare to receive result $raw = ''; $output = array(); while (!feof($ptr)) { // If a buffer size is set, fetch line-by-line into an array if ($this->BUFFER) { $output[] = trim(fgets($ptr, $this->BUFFER)); } else { $raw .= fgetc($ptr); } } // If captured char-by-char, convert to an array of lines if (!$this->BUFFER) { $output = explode("\n", $raw); } // Drop empty last line if (empty($output[count($output) - 1])) { unset($output[count($output) - 1]); } } // Create result and set 'rawdata' $result = array(); $result['rawdata'] = $output; // If we have a handler, post-process it with that if (isset($this->Query['handler'])) { $result = $this->Process($result, $deep_whois); } // Set whois server if (!isset($result['regyinfo']['whois'])) { $result['regyinfo']['whois'] = $this->Query['server']; } // Set whois server full query if (!isset($result['regyinfo']['args'])) { $result['regyinfo']['args'] = $query_args; } // Set whois server port if (!isset($result['regyinfo']['port'])) { $result['regyinfo']['port'] = $this->Query['server_port']; } // Type defaults to domain if (!isset($result['regyinfo']['type'])) { $result['regyinfo']['type'] = 'domain'; } // Add error information if any if (isset($this->Query['errstr'])) { $result['errstr'] = $this->Query['errstr']; } // If no rawdata use rawdata from first whois server if (!isset($result['rawdata'])) { $result['rawdata'] = $output; } // Fix/add nameserver information if (method_exists($this, 'FixResult') && $this->Query['tld'] != 'ip') { $this->FixResult($result, $string); } return $result; }
function GetRawData($query) { $this->Query['query'] = $query; // clear error description if (isset($this->Query['errstr'])) { unset($this->Query['errstr']); } if (!isset($this->Query['server'])) { $this->Query['status'] = -1; $this->Query['errstr'][] = 'No server specified'; return array(); } // Check if protocol is http if (substr($this->Query['server'], 0, 7) == 'http://' || substr($this->Query['server'], 0, 8) == 'https://') { $output = $this->httpQuery($this->Query['server']); if (!$output) { $this->Query['status'] = -1; $this->Query['errstr'][] = 'Connect failed to: ' . $this->Query['server']; return array(); } $this->Query['args'] = substr(strchr($this->Query['server'], '?'), 1); $this->Query['server'] = strtok($this->Query['server'], '?'); if (substr($this->Query['server'], 0, 7) == 'http://') { $this->Query['server_port'] = 80; } else { $this->Query['server_port'] = 483; } } else { // Get args if (strpos($this->Query['server'], '?')) { $parts = explode('?', $this->Query['server']); $this->Query['server'] = trim($parts[0]); $query_args = trim($parts[1]); // replace substitution parameters $query_args = str_replace('{query}', $query, $query_args); $query_args = str_replace('{version}', 'phpWhois' . $this->CODE_VERSION, $query_args); if (strpos($query_args, '{ip}') !== false) { $query_args = str_replace('{ip}', getclientip(), $query_args); } if (strpos($query_args, '{hname}') !== false) { $query_args = str_replace('{hname}', gethostbyaddr(getclientip()), $query_args); } } else { $query_args = $query; } $this->Query['args'] = $query_args; if (substr($this->Query['server'], 0, 9) == 'rwhois://') { $this->Query['server'] = substr($this->Query['server'], 9); } // Get port if (strpos($this->Query['server'], ':')) { $parts = explode(':', $this->Query['server']); $this->Query['server'] = trim($parts[0]); $this->Query['server_port'] = trim($parts[1]); } else { $this->Query['server_port'] = $this->PORT; } // Connect to whois server, or return if failed $ptr = $this->Connect(); if ($ptr < 0) { $this->Query['status'] = -1; $this->Query['errstr'][] = 'Connect failed to: ' . $this->Query['server']; return array(); } if (version_compare(phpversion(), '4.3.0') >= 0) { stream_set_timeout($ptr, $this->STIMEOUT); } // Send query fputs($ptr, trim($query_args) . "\r\n"); // Prepare to receive result $raw = ''; $output = array(); while (!feof($ptr)) { // If a buffer size is set, fetch line-by-line into an array if ($this->BUFFER) { $output[] = trim(fgets($ptr, $this->BUFFER)); } else { $raw .= fgetc($ptr); } } // If captured char-by-char, convert to an array of lines if (!$this->BUFFER) { $output = explode("\n", $raw); } // Drop empty last line (if it's empty! - saleck) if (empty($output[count($output) - 1])) { unset($output[count($output) - 1]); } } return $output; }