IP来源查询php源代码_PHP
P>《追捕》现在已经响当当了,他的成功,在于它的数据库的维护的毅力,
很多软件都在用它的数据,有些改了名字,变成xxx.dat了,嗬嗬,我觉得不太可取,有点儿不地道的感觉。
我的代码也用到了他,改不改名字无所谓了,关键尊重人家的劳动就好了。
在网页上增加一个段简单的代码,就可以显示来访者的地点。
还可以在自己的网站里面写一个个性化的日志,记录ip也记录地点。
效果可以查看 www.fogsun.com 的左边下角.
/**********************************************************************
* IP 来源追踪 Ver 1.1a
* 作者 耙子 pazee@21cn.com http://www.fogsun.com
* 2002/08/10
*
* 程序中的数据库来自《追捕》,请把追捕中wry.dll 拷贝到函数当前目录。
* 追捕的数据库是个的dbf文件,只不过它的扩展名字变成了dll。
* 2000年我在一个偶然的机会发现了他的dll的真实格式,后来的很多文章也提到了此格式,
* 《追捕》的数据文件目前应用非常广泛,很多查IP来源程序的基本都用到了他的数据库。
* 比如有个去广告,能显示IP来源的QQ就使用了他。
* 2001年初写过一个php的函数,但是需要php的dbf模块支持,很多网站并不提供此模块。
* 现在的版本采用二进制的文件读写,不依赖php的dbf的支持了,没有用到
* 任何shell命令.
* 由于数据文件本身是有序的,所以非常方便的采用了折半查找的算法,
* 速度很快,目前的20020325版本的数据库,大约有记录28905条,最多比较14次。
*
* 在此感谢《追捕》作者“冯志宏”
* 有任何问题请于我联系,谢谢! pazee@21cn.com
*
*
* 声明:
* 你可以随意传播、复制、修改此程序,但是请保留此段文字。
* 代码请勿用在商业软件上、请勿用在不正当的地方(这是《追捕》的要求),
* 再次表示谢谢。
***********************************************************************/
// define path of wry.dll
define("DBFILENAME", "wry.dll");
class TRec
{
var $StartIP;
var $EndIP;
var $Country;
var $Local;
}
class TWru
{
var $ip;
var $fp;
var $Rec;
var $DATAFIELDBEGIN= 0xc2;
var $RECORDLENGTH;
// Check IP and Format IP
function FormatIP($ip)
{
$ret= ereg("^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$", $ip, $IPSection);
if ($ret == false)
return -1; // Invild IP
$this->ip= ';
for ($i=1; $i if ($IPSection[$i] > 255)
return -1;
else
$this->ip.= sprintf("%03.0f", $IPSection[$i]). (($i return 0;
}
// read a record from DB
function ReadRec($RecNo)
{
$this->Seek($RecNo);
$buf= fread($this->fp, $this->RECORDLENGTH);
if (strlen($buf) == 0)
{
return 1;
}
$this->Rec->StartIP= (substr($buf, 0, 17));
$this->Rec->EndIP= trim(substr($buf, 17, 22));
$this->Rec->Country= trim(substr($buf, 17+22, 13));
$this->Rec->Local= trim(substr($buf, 17+22+13, 47));
return 0;
}
// Go to Record Number
function Seek($RecNo)
{
return fseek($this->fp, $RecNo * $this->RECORDLENGTH + $this->DATAFIELDBEGIN, SEEK_SET);
}
// Where_are_you Main Fucntion
/*********************************************
* 使用说明
* 参数:
* IP 合法IP地址即可
* szLocal 是保存返回的结果字符串的
* 返回值:
* 此函数有返回值,可以根据返回值自行处理结果
* 0: 查找成功
* -1: 无效的IP
* 1: 打开数据库文件失败
* 2: 数据文件错误(没找到有效记录)
* 3: 未知 IP
**********************************************/
function wru($ip, &$szLocal)
{
$this->Rec= new TRec;
$nRet= 0;
$this->RECORDLENGTH= 17 + 22 + 13 + 47 + 12 + 1;
if ($this->FormatIP($ip) != 0)
{
$szLocal= "InvalidIP";
return -1;
}
$this->fp= fopen(DBFILENAME, "rb");
if ($this->fp == NULL) {
$szLocal= "OpenFileError";
return 1;
}
// Get Record Count
fseek($this->fp, 0, SEEK_END);
$RecordCount= floor((ftell($this->fp) - $this->DATAFIELDBEGIN) / $this->RECORDLENGTH);
if ($RecordCount {
$szLocal= "FileDataError";
$nRet= 2;
}
else
{
$RangB= 0;
$RangE= $RecordCount;
// Match ...
while ($RangB {
$RecNo= floor(($RangB + $RangE) / 2);
$this->ReadRec($RecNo);
if (strcmp($this->ip, $this->Rec->StartIP) >=0 && strcmp($this->ip, $this->Rec->EndIP) break; //Found match record
if (strcmp($this->ip, $this->Rec->StartIP) > 0)
$RangB= $RecNo;
else
$RangE= $RecNo;
}
if (!($RangB {
$szLocal= "UnknowLocal!";
$nRet= 3;
}
else
{ // Match Success
$szLocal= $this->Rec->Country;
$szLocal.= $this->Rec->Local;
}
}
fclose($this->fp);
return $nRet;
}
}
/*******************************************************************
* 变更记录:
* 2002/08/10 完成版本 1.0a
* 2002/08/12 增加FormatIP成员函数,提供了对IP的标准格式化,支持
* 202.96.128.68 这类的写法,类的内部自动转为 202.096.128.068,
* 同时提供了完整的对IP地址的有效检查。规则是4个整数部分均不超
* 过255的自然数。
* ********************************************************************/
?>
// Test Code.
$wru= new TWru;
$szResult="";
$ip= "202.96.134.133";
// $ip= $REMOTE_ADDR;
$wru->wru($ip, $szResult);
echo $ip."
";
echo $szResult;
//---------------------------------------------------------------------------
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

If you want to check the activation date using an Apple mobile phone, the best way is to check it through the serial number in the mobile phone. You can also check it by visiting Apple's official website, connecting it to a computer, and downloading third-party software to check it. How to check the activation date of Apple mobile phone Answer: Serial number query, Apple official website query, computer query, third-party software query 1. The best way for users is to know the serial number of their mobile phone. You can see the serial number by opening Settings, General, About This Machine. . 2. Using the serial number, you can not only know the activation date of your mobile phone, but also check the mobile phone version, mobile phone origin, mobile phone factory date, etc. 3. Users visit Apple's official website to find technical support, find the service and repair column at the bottom of the page, and check the iPhone activation information there. 4. User

Title: How to use Oracle to query whether a table is locked? In Oracle database, table lock means that when a transaction is performing a write operation on the table, other transactions will be blocked when they want to perform write operations on the table or make structural changes to the table (such as adding columns, deleting rows, etc.). In the actual development process, we often need to query whether the table is locked in order to better troubleshoot and deal with related problems. This article will introduce how to use Oracle statements to query whether a table is locked, and give specific code examples. To check whether the table is locked, we

MySQL and PL/SQL are two different database management systems, representing the characteristics of relational databases and procedural languages respectively. This article will compare the similarities and differences between MySQL and PL/SQL, with specific code examples to illustrate. MySQL is a popular relational database management system that uses Structured Query Language (SQL) to manage and operate databases. PL/SQL is a procedural language unique to Oracle database and is used to write database objects such as stored procedures, triggers and functions. same

In today's digital society, Douyin, as a popular social entertainment platform, has attracted the attention and participation of hundreds of millions of users. However, Douyin’s IP territorial positioning has always been one of the topics of interest to users. People are often curious, is Douyin's IP location positioning real-time? What secrets are hidden in this? Let’s dig into it. 1. Is Douyin’s IP location real-time positioning? As a large social platform, Douyin’s IP location has an important impact on user privacy and content push. Under normal circumstances, Douyin's IP location positioning is real-time and can be accurately positioned based on the user's current location. This real-time positioning technology can help Douyin provide users with personalized services more accurately, such as recommending nearby popular content and business
