Program QQwry.dat format analysis and query IP location of the PHP program
by STRONGC http://strongc.51.net/d2x/
Reprint do not remove my name and my homepage link, thank you!
The previous manhunt database was too large and has not been updated for a long time.
So I think of using QQwry.dat this file query IP location, QQwry.dat in many places can be found, the general look at the IP address of the QQ compression package have.
But there is no relevant format information.
I analyzed the format of this document, and now I have the following conclusion:
The format is as follows:
A. File header, total 8 bytes
B. End address of several records + country and region
C. Fixed length, 7 bytes by starting address + End address offset from small to large arrangement
D. All IP is recorded in 4-byte integers, and is in the Intel order, high on the back, low in front.
E. All offsets are absolute offsets, which are computed from the beginning of the file.
F. In addition to the file header with two 4 byte offsets, the remaining offsets are in 3 bytes.
G. All offsets are low in the front, high on the back
H. Some string compression techniques are used
1. File header, total 8 bytes
Firststartipoffset:4 the absolute offset of the first starting IP
Laststartipoffset:4 the absolute offset of the last originating IP
2. Start address + End address offset record area
7 bytes per record, from small to large by start address
Startip:4 start address, integer form of IP
Endipoffset:3 End Address Absolute offset
3. End Address + country + Area record area
Endip:4
Country + Regional record: indefinite length
4. National + Regional Records, there are several forms
4.1.
Country string, ending with 0x0
Area string, ending with 0x0
4.2.
Flag:1 Identity value: 0x1, no local records after
0x2, there's a local record back there.
Scountryoffset:3 the actual string is going to this offset position to find
Localrec: Indefinite length, optional according to flag value. This record is similar to country and may be compressed
4.3 LOCALREC structure A
Flag:1 is not quite aware of this flag meaning, 0x1 or 0x2
Slocaloffset:3
4.4 LOCALREC Structure II
Slocal: Indefinite long normal C-style string
Note: The location of the Scountryoffset point may still be in the 4.2 format, and I don't know why.
Flag take 0x1, Scountryoffset point to the location may be flag for 0x2, at this time, Localrec also here to find.
Now I don't understand what it means to record the location of the local to the 0X2 flag.
There seem to be some errors in the Qqwry.dat.
Individual records local will be written as:
0x2,0x0,0x0,0x0
According to the rules, you should go to the beginning of the file to look for it, however, the first document is obviously not record these.
I learned PHP soon, you do not laugh, you have to improve of course good, remember to give me a copy.
I refer to some of the code found on the Internet, I do not write the source.
To tell you the truth, I have a headache. PHP cannot explicitly specify the type of the variable.
For example, I want to make a number is an unsigned plastic surgery, it is very disobedient, not if with a minus sign, I have to try all kinds of possible writing ...
How do you guys deal with something like that?
Class Tqqwry
{
var $StartIP = 0;
var $EndIP = 0;
var $Country = ';
var $Local = ';
var $CountryFlag = 0; Identify Country Location
0x01, followed by a 3 byte country offset, no local
0x02, followed by a country offset of 3 bytes, followed by local
Other, country,local,local have similar compression. may be multiple references.
var $fp;
var $FirstStartIp = 0;
var $LastStartIp = 0;
var $EndIpOff = 0;
function Ip2location ($IP)
{
$wry = new Tqqwry;
$nRet = $wry->qqwry ($IP);
can use $nRet to do something, I was let him automatically record unknown IP to a table, the code is not written.
Return $wry->country. $wry->local;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.