'', 'type' => 'domain', 'query' => '', 'status', 'server' ); // This release of the package var $CODE_VERSION = '4.2.2'; // Full code and data version string (e.g. 'Whois2.php v3.01:16') var $VERSION; /* * Constructor function */ function WhoisClient () { // Load DATA array @require('whois.servers.php'); // Set version $this->VERSION = sprintf("phpWhois v%s-%s", $this->CODE_VERSION, $this->DATA_VERSION); } /* * Perform lookup */ 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'] = 'error'; $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'] = 'error'; $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}', phpwhois_getclientip(), $query_args); } if (strpos($query_args,'{hname}')!==false) { $query_args = str_replace('{hname}', gethostbyaddr(phpwhois_getclientip()), $query_args); } } else { if (empty($this->Query['args'])) $query_args = $query; else $query_args = $this->Query['args']; } $this->Query['args'] = $query_args; if (substr($this->Query['server'],0,9) == 'rwhois://') { $this->Query['server'] = substr($this->Query['server'],9); } if (substr($this->Query['server'],0,8) == 'whois://') { $this->Query['server'] = substr($this->Query['server'],8); } // 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'] = 'error'; $this->Query['errstr'][] = 'Connect failed to: '.$this->Query['server']; return array(); } stream_set_timeout($ptr,$this->STIMEOUT); stream_set_blocking($ptr,0); // Send query fputs($ptr, trim($query_args)."\r\n"); // Prepare to receive result $raw = ''; $start = time(); $null = NULL; $r = array($ptr); while (!feof($ptr)) { if (stream_select($r,$null,$null,$this->STIMEOUT)) { $raw .= fgets($ptr, $this->BUFFER); } if (time()-$start > $this->STIMEOUT) { $this->Query['status'] = 'error'; $this->Query['errstr'][] = 'Timeout reading from '.$this->Query['server']; return array(); } } if (array_key_exists($this->Query['server'],$this->NON_UTF8)) { $raw = utf8_encode($raw); } $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; } /* * Perform lookup. Returns an array. The 'rawdata' element contains an * array of lines gathered from the whois query. If a top level domain * handler class was found for the domain, other elements will have been * populated too. */ function GetData ($query='', $deep_whois=true) { // If domain to query passed in, use it, otherwise use domain from initialisation $query = !empty($query) ? $query : $this->Query['query']; $output = $this->GetRawData($query); // Create result and set 'rawdata' $result = array( 'rawdata' => $output ); $result = $this->set_whois_info($result); // Return now on error if (empty($output)) return $result; // If we have a handler, post-process it with it if (isSet($this->Query['handler'])) { // Keep server list $servers = $result['regyinfo']['servers']; unset($result['regyinfo']['servers']); // Process data $result = $this->Process($result,$deep_whois); // Add new servers to the server list if (isset($result['regyinfo']['servers'])) $result['regyinfo']['servers'] = array_merge($servers,$result['regyinfo']['servers']); else $result['regyinfo']['servers'] = $servers; // Handler may forget to set rawdata if (empty($result['rawdata'])) $result['rawdata'] = $output; } // 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']; // Fix/add nameserver information if (method_exists($this,'FixResult') && $this->Query['tld'] != 'ip') $this->FixResult($result,$query); return($result); } /* * Adds whois server query information to result */ function set_whois_info ($result) { $info = array( 'server'=> $this->Query['server'], ); if (!empty($this->Query['args'])) $info['args'] = $this->Query['args']; else $info['args'] = $this->Query['query']; if (!empty($this->Query['server_port'])) $info['port'] = $this->Query['server_port']; else $info['port'] = 43; if (isset($result['regyinfo']['whois'])) unset($result['regyinfo']['whois']); if (isset($result['regyinfo']['rwhois'])) unset($result['regyinfo']['rwhois']); $result['regyinfo']['servers'][] = $info; return $result; } /* * Convert html output to plain text */ function httpQuery ($query) { //echo ini_get('allow_url_fopen'); //if (ini_get('allow_url_fopen')) $lines = @file($this->Query['server']); if (!$lines) return false; $output = ''; $pre = ''; while (list($key, $val)=each($lines)) { $val = trim($val); $pos=strpos(strtoupper($val),'
'); if ($pos!==false) { $pre = "\n"; $output.=substr($val,0,$pos)."\n"; $val = substr($val,$pos+5); } $pos=strpos(strtoupper($val),''); if ($pos!==false) { $pre = ''; $output.=substr($val,0,$pos)."\n"; $val = substr($val,$pos+6); } $output.=$val.$pre; } $search = array ( '
', '',
'', '', '',
'
', '
', '', '', '', '' ); $output = str_replace($search,"\n",$output); $output = str_replace('