⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip2add.php

📁 极限网络智能办公系统 Office Automation V3.0官方100%源代码.
💻 PHP
字号:
<?php
 
class tqqwry
{

	var $StartIP = 0;
	var $EndIP = 0;
	var $Country = "";
	var $Local = "";
	var $CountryFlag = 0;
	var $fp;
	var $FirstStartIp = 0;
	var $LastStartIp = 0;
	var $EndIpOff = 0;

	function getstartip( $RecNo )
	{
		$offset = $this->FirstStartIp + $RecNo * 7;
		@fseek( $this->fp, $offset, SEEK_SET );
		$buf = fread( $this->fp, 7 );
		$this->EndIpOff = ord( $buf[4] ) + ord( $buf[5] ) * 256 + ord( $buf[6] ) * 256 * 256;
		$this->StartIp = ord( $buf[0] ) + ord( $buf[1] ) * 256 + ord( $buf[2] ) * 256 * 256 + ord( $buf[3] ) * 256 * 256 * 256;
		return $this->StartIp;
	}

	function getendip( )
	{
		@fseek( $this->fp, $this->EndIpOff, SEEK_SET );
		$buf = fread( $this->fp, 5 );
		$this->EndIp = ord( $buf[0] ) + ord( $buf[1] ) * 256 + ord( $buf[2] ) * 256 * 256 + ord( $buf[3] ) * 256 * 256 * 256;
		$this->CountryFlag = ord( $buf[4] );
		return $this->EndIp;
	}

	function getcountry( )
	{
		switch ( $this->CountryFlag )
		{
		case 1 :
		case 2 :
			$this->Country = $this->getflagstr( $this->EndIpOff + 4 );
			$this->Local = 1 == $this->CountryFlag ? "" : $this->getflagstr( $this->EndIpOff + 8 );
			break;
		default :
			$this->Country = $this->getflagstr( $this->EndIpOff + 4 );
			$this->Local = $this->getflagstr( ftell( $this->fp ) );
		}
	}

	function getflagstr( $offset )
	{
		$flag = 0;
		do
		{
			@fseek( $this->fp, $offset, SEEK_SET );
			$flag = ord( fgetc( $this->fp ) );
			$buf = fread( $this->fp, 3 );
			if ( $flag == 2 )
			{
				$this->CountryFlag = 2;
				$this->EndIpOff = $offset - 4;
			}
			$offset = ord( $buf[0] ) + ord( $buf[1] ) * 256 + ord( $buf[2] ) * 256 * 256;
			continue;
			break;
		} while ( 1 );
		if ( $offset < 12 )
		{
			return "";
		}
		@fseek( $this->fp, $offset, SEEK_SET );
		return $this->getstr( );
	}

	function getstr( )
	{
		$str = "";
		do
		{
			$c = fgetc( $this->fp );
			if ( ord( $c[0] ) == 0 )
			{
				break;
			}
			else
			{
				$str .= $c;
			}
		} while ( 1 );
		return $str;
	}

	function qqwry( $dotip )
	{
		$ip = iptoint( $dotip );
		$this->fp = @fopen( QQWRY, "rb" );
		if ( $this->fp == NULL )
		{
			$szLocal = "OpenFileError";
			return 1;
		}
		@fseek( $this->fp, 0, SEEK_SET );
		$buf = fread( $this->fp, 8 );
		$this->FirstStartIp = ord( $buf[0] ) + ord( $buf[1] ) * 256 + ord( $buf[2] ) * 256 * 256 + ord( $buf[3] ) * 256 * 256 * 256;
		$this->LastStartIp = ord( $buf[4] ) + ord( $buf[5] ) * 256 + ord( $buf[6] ) * 256 * 256 + ord( $buf[7] ) * 256 * 256 * 256;
		$RecordCount = floor( ( $this->LastStartIp - $this->FirstStartIp ) / 7 );
		if ( $RecordCount <= 1 )
		{
			$this->Country = "FileDataError";
			fclose( $this->fp );
			return 2;
		}
		$RangB = 0;
		$RangE = $RecordCount;
		while ( $RangB < $RangE - 1 )
		{
			$RecNo = floor( ( $RangB + $RangE ) / 2 );
			$this->getstartip( $RecNo );
			if ( $ip == $this->StartIp )
			{
				$RangB = $RecNo;
			}
			else if ( $this->StartIp < $ip )
			{
				$RangB = $RecNo;
			}
			else
			{
				$RangE = $RecNo;
			}
		}
		$this->getstartip( $RangB );
		$this->getendip( );
		if ( $this->StartIp <= $ip && $ip <= $this->EndIp )
		{
			$nRet = 0;
			$this->getcountry( );
			$this->Local = str_replace( "(我们一定要解放台湾!!!)", "", $this->Local );
		}
		else
		{
			$nRet = 3;
			$this->Country = "未知";
			$this->Local = "";
		}
		fclose( $this->fp );
		return $nRet;
	}

}

function iptoint( $Ip )
{
	$array = explode( ".", $Ip );
	$Int = $array[0] * 256 * 256 * 256 + $array[1] * 256 * 256 + $array[2] * 256 + $array[3];
	return $Int;
}

function inttoip( $Int )
{
	$b1 = ( $Int & 4.27819e+009 ) >> 24;
	if ( $b1 < 0 )
	{
		$b1 += 256;
	}
	$b2 = ( $Int & 16711680 ) >> 16;
	if ( $b2 < 0 )
	{
		$b2 += 256;
	}
	$b3 = ( $Int & 65280 ) >> 8;
	if ( $b3 < 0 )
	{
		$b3 += 256;
	}
	$b4 = $Int & 255;
	if ( $b4 < 0 )
	{
		$b4 += 256;
	}
	$Ip = $b1.".".$b2.".".$b3.".".$b4;
	return $Ip;
}

function convertip( $ip )
{
	$wry = new tqqwry( );
	$nRet = $wry->qqwry( $ip );
	return $wry->Country.$wry->Local;
}

include_once( "inc/oa_config.php" );
$IP_FILE = $ROOT_PATH."inc/QQWry.Dat";
define( "QQWRY", $IP_FILE );
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -