


PHP read qqwry.dat ip address database file program_PHP tutorial
The article first introduces the file content structure of qqwry.dat. Then according to its characteristics, we can write to read the content of the qqwry.dat ip library to find the content we want.
First, let’s take a look at the content structure of the QQWry.Data file and how to interpret it.
1. File structure
Files are mainly divided into three structures
1. File header, 8 bytes;
2. Data recording area, variable length;
3. Index Area, the length is an integer multiple of 7;
2. File header
The 8 bytes of the file header are divided into two parts, each part is 4 bytes, respectively specifying the starting address and the index area end address. Therefore, the total number of records can be calculated by dividing the difference between the two addresses by 7 and then adding 1.
2. Recording area
The data in the recording area needs to obtain the starting position of each data through the data in the index area; the data in this area records the end address of the IP address and the region string; all regional characters Strings end with 0×00.
3. Index area
To retrieve the area corresponding to the IP, the key is to find the index content corresponding to the IP starting address. An IP index data contains 7 bytes, the first 4 bytes are the starting value of the IP address, and the last 3 bytes are the offset address of the corresponding IP data record in the file; in the IP data record, the first 4 bytes The stanza is the IP end address; the data that follows has two patterns: 0×01 pattern and 0×02 pattern.
0×01 mode, that is, the 5th byte of the IP data is 0×01, and the next 3 bytes are the offset address of the country and region data; the country and region data includes the country and region these two strings. That is,
————————————————————
4 bytes | 3 bytes redirection 0x NN NN NN -> File offset of country and region data Shift address
————————————————————
0×02 mode, that is, the 5th byte of IP data is 0× 02, then the next 3 bytes are the offset address of the national data, and the regional data is the following string, ending with 0×00. i.e.
——————————————————————————–
4 bytes | 3 bytes Redirect 0x NN NN NN -> Country File offset address of data | Region string | 0×00
————————————————————————————–
for In the country and region data obtained by the 0×01 pattern, it may also contain a redirection structure, that is,
————————————–
Country string | 0×00 | Region string | 0×00
————————————–
or
—————————————————— ————-
Country string | 0×00 | 0×02 | 3 bytes 0x NN NN NN -> File offset address of region string
—————————— ————————————————-
For the former case, it is relatively simple, just read the two string data directly; for the latter case, you need Redirect again to the offset address of the region string, and then read to 0×00 as the end of the string.
For this method of mapping actual string values by address, the main function is to avoid repeated recording of string values. There are too many identical string records in the entire IP address library file. Using a 3-byte mapped address saves much space than repeatedly recording string values.
PHP code reading operation QQWry.dat file:
The code is as follows | Copy code |
function bin2ip($bin){ //------------------------ -------------------------------- $index_begin = implode('', unpack('L', $c)); $ip_num = ($index_end - $index_begin) / 7 + 1; echo "index begin at: $index_beginn"; $output = ''; for($i = 0; $i < $ip_num; $i++){ //The file pointer points to each Get the index data (7 bytes) of the IP data file on $ip3 = fread($f, 3); //IP record offset address $dataseek = implode('', unpack('L', $ip3 . chr(0)) ); //Point to the record area $dataseek location to find the record $area = ''; //Read a flag bit $flag = fread($f, 1) ; //If the area is redirected |
This function we What I see most are the file operation related functions such as fopen, fseek, and fread. Friends in need can take a look.

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.
