-
<?php
-
-
class TQQwry
-
{
-
var $StartIp = 0;
-
var $EndIp = 0;
-
var $Country = ”;
-
var $Local = ”;
-
-
var $CountryFlag = 0; // 标识 Country位置
-
// 0×01,随后3字节为Country偏移,没有Local
-
// 0×02,随后3字节为Country偏移,接着是Local
-
// 其他,Country,Local,Local有类似的压缩。可能多重引用。
-
var $fp;
-
-
var $FirstStartIp = 0;
-
var $LastStartIp = 0;
-
var $EndIpOff = 0 ;
-
-
function getStartIp ( $RecNo ) {
-
$offset = $this->FirstStartIp + $RecNo * 7 ;
-
return $this->StartIp ;
-
}
-
-
function getEndIp ( ) {
-
return $this->EndIp ;
-
}
-
-
function getCountry ( ) {
-
-
switch ( $this->CountryFlag ) {
-
case 1:
-
case 2:
-
$this->Local = ( 1 == $this->CountryFlag )? ” : $this->getFlagStr ( $this->EndIpOff+8);
-
break ;
-
default :
-
-
}
-
}
-
-
-
function getFlagStr ( $offset )
-
{
-
-
$flag = 0 ;
-
while ( 1 ){
-
if ( $flag == 1 || $flag == 2 ) {
-
if ($flag == 2 ){
-
$this->CountryFlag = 2 ;
-
$this->EndIpOff = $offset – 4 ;
-
}
-
}else{
-
break ;
-
}
-
-
}
-
if ( $offset < 12 )
-
return ”;
-
return $this->getStr();
-
}
-
function getStr ( )
-
{
-
$str = ” ;
-
while ( 1 ) {
-
break ;
-
$str .= $c ;
-
}
-
return $str ;
-
}
-
-
-
function qqwry ($dotip) {
-
$nRet;
-
if ($this->fp == NULL) {
-
$szLocal= "OpenFileError";
-
return 1;
-
-
}
-
-
if ($RecordCount <= 1){
-
$this->Country = "FileDataError";
-
return 2 ;
-
}
-
$RangB= 0;
-
$RangE= $RecordCount;
-
// Match …
-
while ($RangB < $RangE-1)
-
{
-
$this->getStartIp ( $RecNo ) ;
-
-
if ( $ip == $this->StartIp )
-
{
-
$RangB = $RecNo ;
-
break ;
-
}
-
if ( $ip > $this->StartIp)
-
$RangB= $RecNo;
-
else
-
$RangE= $RecNo;
-
}
-
$this->getStartIp ( $RangB ) ;
-
$this->getEndIp ( ) ;
-
-
if ( ( $this->StartIp <= $ip ) && ( $this->EndIp >= $ip ) ){
-
$nRet = 0 ;
-
$this->getCountry ( ) ;
-
//这样不太好…………..所以……….
-
-
}else {
-
$nRet = 3 ;
-
$this->Country = ‘未知’ ;
-
$this->Local = ” ;
-
}
-
return $this->Country.‘ ‘.$this->Local ;
-
}
-
}
-
-
-
$wry = new TQQwry ;
-
?>
QQWry.Dat读取
- No comments yet.
- No trackbacks yet.
Recent Comments