* Date: 8/19/14 * Time: 12:01 PM */ ?> <div> <p><?php echo Yii::t('app', 'User IP'); ?> </p> <pre><?php echo IpTools::GET_USER_IP(); ?> </pre> <p><?php echo Yii::t('app', 'Format IP to database'); ?> </p> <pre><?php echo IpTools::GET_USER_IP() . ' -> ' . IpTools::GET_USER_IP_BDD_FORMAT(); ?> </pre> <p><?php echo Yii::t('app', 'Get the IP information'); ?> </p> <pre><?php print_r(IpTools::GET_IP_DATA_EXTERNAL_SOURCE(false)); ?> </pre> </div>
/** * Guess query type * * @param string $query * * @return int Query type */ public function getQueryType($query) { $ipTools = new IpTools(); if ($ipTools->validIp($query, 'ipv4', false)) { if ($ipTools->validIp($query, 'ipv4')) { return self::QTYPE_IPV4; } else { return self::QTYPE_UNKNOWN; } } elseif ($ipTools->validIp($query, 'ipv6', false)) { if ($ipTools->validIp($query, 'ipv6')) { return self::QTYPE_IPV6; } else { return self::QTYPE_UNKNOWN; } } elseif (!empty($query) && strpos($query, '.') !== false) { return self::QTYPE_DOMAIN; } elseif (!empty($query) && strpos($query, '.') === false) { return self::QTYPE_AS; } else { return self::QTYPE_UNKNOWN; } }
/** * Perform lookup * * @return array Raw response as array separated by "\n" */ public function getRawData($query) { $this->query['query'] = $query; // 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->codeVersion, $query_args); $iptools = new IpTools(); if (strpos($query_args, '{ip}') !== false) { $query_args = str_replace('{ip}', $iptools->getClientIp(), $query_args); } if (strpos($query_args, '{hname}') !== false) { $query_args = str_replace('{hname}', gethostbyaddr($iptools->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 === false) { $this->query['status'] = 'error'; $this->query['errstr'][] = 'Connect failed to: ' . $this->query['server']; return []; } 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 = [$ptr]; while (!feof($ptr)) { if (!empty($r)) { 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 []; } } $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; }