<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */

 class ip { private $uq0; private $uq1; private $uq2; private $uq3; public function __construct() { $uq4 = UQCMS_PATH.'data'.DS.'qqwry.dat'; $this->fp = 0; if (($this->fp = fopen($uq4, 'rb')) !== false) { $this->firstip = $this->getlong(); $this->lastip = $this->getlong(); $this->totalip = ($this->lastip - $this->firstip)/7; register_shutdown_function(array(&$this, '__destruct')); } } public function __destruct() { if ($this->fp) { fclose($this->fp); } $this->fp = 0; } private function getlong() { $uq5 = unpack('Vlong', fread($this->fp, 4)); return $uq5['long']; } private function getlong3() { $uq5 = unpack('Vlong', fread($this->fp, 3) . chr(0)); return $uq5['long']; } private function packip($uq6) { return pack('N', intval(ip2long($uq6))); } private function getstring($uq7 = "") { $uq8 = fread($this->fp, 1); while (ord($uq8) > 0) { $uq7 .= $uq8; $uq8 = fread($this->fp, 1); } return iconv('gbk', 'utf-8', $uq7); } private function getarea() { $uq9 = fread($this->fp, 1); switch (ord($uq9)) { case 0: $uq10 = ""; break; case 1: case 2: fseek($this->fp, $this->getlong3()); $uq10 = $this->getstring(); break; default: $uq10 = $this->getstring($uq9); break; } return $uq10; } public function get($uq6) { if(!$this->fp){ return null; } $uq11['ip'] = gethostbyname($uq6); $uq6 = $this->packip($uq11['ip']); $uq12 = 0; $uq13 = $this->totalip; $uq14 = $this->lastip; while ($uq12 <= $uq13) { $uq15 = floor(($uq12 + $uq13) / 2); fseek($this->fp, $this->firstip + $uq15 * 7); $uq16 = strrev(fread($this->fp, 4)); if ($uq6 < $uq16) { $uq13 = $uq15 - 1; } else { fseek($this->fp, $this->getlong3()); $uq17 = strrev(fread($this->fp, 4)); if ($uq6 > $uq17) { $uq12 = $uq15 + 1; } else { $uq14 = $this->firstip + $uq15 * 7; break; } } } fseek($this->fp, $uq14); $uq11['beginip'] = long2ip($this->getlong()); $uq18 = $this->getlong3(); fseek($this->fp, $uq18); $uq11['endip'] = long2ip($this->getlong()); $uq9 = fread($this->fp, 1); switch(ord($uq9)){ case 1: $uq19 = $this->getlong3(); fseek($this->fp, $uq19); $uq9 = fread($this->fp, 1); switch (ord($uq9)) { case 2: fseek($this->fp, $this->getlong3()); $uq11['country'] = $this->getstring(); fseek($this->fp, $uq19 + 4); $uq11['area'] = $this->getarea(); break; default: $uq11['country'] = $this->getstring($uq9); $uq11['area'] = $this->getarea(); break; } break; case 2: fseek($this->fp, $this->getlong3()); $uq11['country'] = $this->getstring(); fseek($this->fp, $uq18 + 8); $uq11['area'] = $this->getarea(); break; default: $uq11['country'] = $this->getstring($uq9); $uq11['area'] = $this->getarea(); break; } if ($uq11['country'] == " CZ88.NET-未提供") { $uq11['country'] = "未知"; } if ($uq11['area'] == " CZ88.NET-未提供") { $uq11['area'] = ""; } return $uq11; } } 