Web chasing PHP version source code

xiaoxiao2021-03-06  62

Web chasing PHP version source code

/ ************************************************** ********************

* IP Source Tracking Ver 1.1a

* Author 耙子 paze@21cn.com http://www.fogsun.com

* 2002/08/10

*

* The database in the program comes from "pursuing". Please copy the wry.dll in the champion to the current directory.

* The pursued database is a DBF file, but its extension name turns a DLL.

* In 2000, I found a real format of his DLL in an accidental opportunity. Many of the articles mentioned in this format.

* The data file "chasing" is currently applying very widely, and many of the basic IP source programs have basically used his database.

* If there is an advertisement, you can display the QQ of the IP source to use him.

* A PHP function is written in early 2001, but the PHP's DBF module is required, and many websites do not provide this module.

* The current version is read and written in binary files, does not rely on the support of PHP DBF, is not used

* Any shell command.

* Since the data file itself is ordered, it is very convenient to use a discrete algorithm.

* The speed is very fast, the current 20020325 version of the database, about 28,905 records, up to 14 times.

*

* Thanks to the author "Feng Zhihong" by the author "

* If you have any questions, please contact me, thank you! PAZEE@21cn.com

*

*

* Declaration:

* You can spread, copy, modify this program, but keep this paragraph.

* Code Do not use it on commercial software, do not use in an improper place (this is "chasing" requirements),

* Re-expressed thank you.

*********************************************************** ******************** /

// 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 $ R;

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 <= 4; $ i )

IF ($ IPSECTION [$ I]> 255)

Return -1;

Else

$ this-> ip. = Sprintf ("% 03.0f", $ IPSECTION [$ I]). (($ I <4)? '.': ');');

Return 0;

}

// read a replaord 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

/ ***************************************************

* Instructions for use

* Parameters:

* IP legal IP address

* Szlocal is a string of the result of the returned result

* return value:

* This function has a return value, which can process the result according to the return value.

* 0: Find success

* -1: Invalid IP

* 1: Open the database file failed

* 2: Data file error (did not find a valid record)

* 3: Unknown 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 (($ this-> fp) - $ this-> datafieldbegin / $ this-> recordlength);

IF ($ RecordCount <= 1)

{

$ Szlocal = "FileDataError";

$ nret = 2;

}

Else

{

$ RANGB = 0;

$ RANGE = $ RecordCount;

// match ...

While ($ RANGB <$ RANGE-1)

{

$ Recno = floor ($ RANGB $ RANGE) / 2);

$ this-> Readrec ($ Recno);

IF (STRCMP ($ this-> IP, $ this-> Rec-> startip> = 0 && strcmp ($ this-> ip, $ this-> r-> endip) <= 0) Break; // Found Match Record

IF (STRCMP ($ this-> ip, $ this-> r-> startip)> 0)

$ Rangb = $ Recno;

Else

$ RANGE = $ Recno;

}

IF ($ rangb <$ range-1)))

{

$ szlocal = "unknowlocal!";

$ nret = 3;

}

Else

{// Match SUCCESS

$ szlocal = $ this-> r-> country;

$ szlocal. = $ this-> r-> local;

}

}

Fclose ($ THIS-> FP);

Return $ nret;

}

}

/ ************************************************** ******************

* change log:

* 2002/08/10 Complete version 1.0A

* 2002/08/12 Increase the Formatip member function, provides standard formatting, support for IP

* 202.96.128.68 This type of writing, the internal automatic transfer of 202.096.128.068,

* At the same time, a complete valid check for IP addresses is available. The rule is that the four integer parts are not super

* The natural number of 255 is over 255.

* ********************************************************** ****************** /

// Below, IT IS Test Code.

$ WRU = New TWRU;

$ SzResult = ""

$ IP = "202.96.134.133";

// $ ip = $ transote_addr;

$ WRU-> WRU ($ IP, $ SzResult);

Echo $ IP. "
";

Echo $ szResult;

/ / -------------------------------------------------------------------------------------------- ---------------------------

?>

转载请注明原文地址:https://www.9cbs.com/read-111734.html

New Post(0)