A data processing method and device based on IP address range

By constructing a binary tree based on IP address ranges, the insertion position of the IP address range can be quickly determined, solving the problems of high maintenance cost and slow storage and matching efficiency in existing network blocking methods, and achieving efficient and accurate network blocking matching.

CN115955341BActive Publication Date: 2026-04-28BEIJING TOPSEC NETWORK SECURITY TECH +2
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING TOPSEC NETWORK SECURITY TECH
Filing Date
2022-12-19
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing network blocking methods rely on a large number of IP addresses, resulting in high maintenance costs and slow storage and matching efficiency.

Method used

By obtaining the common prefix and length of the starting and ending IP addresses within the IP address range, a temporary node is generated. This temporary node is then compared with the target node of the binary tree to determine the insertion position. Finally, the temporary node is inserted into the binary tree to construct the updated binary tree.

Benefits of technology

It improves the construction speed and matching efficiency of binary trees, reduces network maintenance costs, and ensures matching accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115955341B_ABST
    Figure CN115955341B_ABST
Patent Text Reader

Abstract

The application provides an IP address range-based data processing method and device. The IP address range-based data processing method comprises the following steps: obtaining a first IP address range; determining a common prefix of a start IP and an end IP of the first IP address range and a length of the common prefix; generating a temporary node based on the common prefix and the length; comparing the temporary node with a target node of a binary tree to determine a target position to which the temporary node is to be inserted into the binary tree; wherein the binary tree comprises at least a plurality of nodes storing attribute characteristics of different IP address ranges; inserting the temporary node into the binary tree at the target position and storing attribute characteristics of the first IP address range to the temporary node to obtain an updated binary tree. The above-mentioned method can quickly update and construct the binary tree, and the binary tree constructed in this way has the advantages of high matching efficiency and high matching accuracy when matching with a received message, thereby effectively reducing the cost of maintaining a network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Internet technology, and in particular to a data processing method and apparatus based on IP address range. Background Technology

[0002] An IP address is a standardized address provided by the Internet Protocol (IP). Every device on the Internet is assigned a unique IP address, and communication is based on this IP address. With the development of the Internet, various network attacks are emerging, making the protection of internal servers, hosts, and other assets particularly important. Network blocking is the most basic and effective protection method. However, the larger the number of IP addresses required to achieve network blocking, the higher the maintenance costs, storage, and matching efficiency become. Summary of the Invention

[0003] To address the aforementioned technical problems in the prior art, this disclosure provides a data processing method and apparatus based on IP address range, which can solve the problems of maintenance costs, slow storage and matching efficiency caused by network blocking in the prior art.

[0004] This disclosure provides a data processing method based on IP address range, including:

[0005] Obtain the first IP address range;

[0006] Determine the common prefix of the starting and ending IP addresses of the first IP address range, as well as the length of the common prefix;

[0007] A temporary node is generated based on the common prefix and its length;

[0008] The temporary node is compared with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges;

[0009] The temporary node is inserted into the binary tree at the target position, and the attribute features of the first IP address range are stored in the temporary node to obtain the updated binary tree.

[0010] In some embodiments, comparing the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree specifically includes:

[0011] If the current node of the binary tree is not equal to the temporary node, then the temporary node is inserted into the binary tree.

[0012] In some embodiments, after determining to insert the temporary node into the binary tree, the method further includes:

[0013] If the common prefix length of the temporary node is less than the common prefix length of the current node, the temporary node is inserted as the parent node of the current node.

[0014] The current node is inserted into the right or left child node of the temporary node based on the length of the common prefix of the temporary node.

[0015] In some embodiments, determining whether the current node is inserted as the right or left child of the temporary node based on the common prefix length of the temporary node specifically includes:

[0016] The length of the common prefix of the temporary node is added to the first value to obtain the value N;

[0017] If the Nth bit of the current node is 1, insert the current node into the right child node of the temporary node;

[0018] If the Nth bit of the current node is 0, insert the current node into the left child node of the temporary node.

[0019] In some embodiments, after determining to insert the temporary node into the binary tree, the method further includes:

[0020] If the common prefix length of the temporary node is greater than the common prefix length of the current node, the temporary node is inserted as a child node of the current node.

[0021] The temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node.

[0022] In some embodiments, determining whether the temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node specifically includes:

[0023] Add the length of the common prefix of the current node to the first value to obtain the value M;

[0024] If the Mth bit of the temporary node is 1, the temporary node is inserted into the right child node of the current node;

[0025] If the Mth bit of the temporary node is 0, the temporary node is inserted into the left child node of the current node.

[0026] In some embodiments, the method further includes:

[0027] Obtain the target IP address corresponding to the received message;

[0028] Determine the common prefix and common prefix length of the target IP address;

[0029] Starting from the root node of the updated binary tree, perform a level-order traversal and compare the current node of the binary tree with the target IP address;

[0030] The matching result of the target IP address and the IP address range stored in the current node of the binary tree is determined based on the comparison result between the current node of the binary tree and the target IP address.

[0031] In some embodiments, determining the matching result between the target IP address and the IP address range stored in at least one node of the binary tree based on the comparison result between the current node of the binary tree and the target IP address specifically includes:

[0032] If the common prefix length of the current node of the binary tree is less than or equal to the common prefix length of the target IP address, determine whether the common prefix length of the current node of the binary tree and the common prefix length of the target IP address are equal.

[0033] If so, generate a matching result indicating successful prefix matching, and match the target IP address with the IP address range;

[0034] If not, then generate a match result where the prefix match failed.

[0035] In some embodiments, matching the target IP address with the IP address range specifically includes:

[0036] Determine whether the IP address range includes the target IP address;

[0037] If so, generate a matching result where the target IP address matches the current node;

[0038] If not, generate a matching result indicating that the target IP address and the current node failed to match, and compare the target IP address with the right or left child node of the current node in the binary tree.

[0039] This disclosure also provides a data processing apparatus based on an IP address range, including:

[0040] The acquisition module is configured to acquire the first IP address range.

[0041] The determining module is configured to determine the common prefix of the start and end IPs of the first IP address range, and the length of the common prefix;

[0042] A generation module, configured to generate temporary nodes based on the common prefix and its length;

[0043] A comparison module is configured to compare the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges;

[0044] An insertion module is configured to insert the temporary node into the binary tree at the target position and store the attribute features of the first IP address range into the temporary node to obtain an updated binary tree.

[0045] Compared with the prior art, the beneficial effects of the embodiments of this disclosure are as follows: This disclosure obtains a temporary node by determining the common prefix of the starting IP and ending IP of the first IP address range, as well as the length of the common prefix. The temporary node is compared with the target node on the binary tree to determine the target position to which the temporary node should be inserted on the binary tree. Then, the temporary node is inserted into the binary tree at the target position to obtain an updated binary tree. The above-mentioned update and construction of the binary tree is faster, and the binary tree constructed in this way has the advantages of high matching efficiency and accurate matching when matching with received packets, which can effectively reduce the cost of maintaining the network. Attached Figure Description

[0046] In drawings that are not necessarily drawn to scale, the same reference numerals may describe similar parts in different views. The same reference numerals with or without letter suffixes may indicate different instances of similar parts. The drawings generally illustrate various embodiments by way of example rather than limitation and are used, together with the description and claims, to illustrate the disclosed embodiments. Where appropriate, the same reference numerals are used in all drawings to refer to the same or similar parts. Such embodiments are illustrative and not intended to be exhaustive or exclusive embodiments of the apparatus or method.

[0047] Figure 1 This is a first flowchart of a data processing method based on IP address range according to an embodiment of the present invention;

[0048] Figure 2 This is a second flowchart of the data processing method based on IP address range according to an embodiment of the present invention;

[0049] Figure 3 This is a third flowchart of the data processing method based on IP address range according to an embodiment of the present invention;

[0050] Figure 4This is a structural block diagram of a data processing device based on an IP address range according to an embodiment of the present invention.

[0051] The components indicated by the reference numerals in the figure:

[0052] 100 - Data processing device based on IP address range; 101 - Acquisition module; 102 - Determination module; 103 - Generation module; 104 - Comparison module; 105 - Insertion module. Detailed Implementation

[0053] Various aspects and features of the present invention are described herein with reference to the accompanying drawings.

[0054] It should be understood that various modifications can be made to the embodiments of the invention described herein. Therefore, the above description should not be considered as limiting, but merely as an example of embodiments. Other modifications within the scope and spirit of the invention will be apparent to those skilled in the art.

[0055] The accompanying drawings, which are included in and form part of this specification, illustrate embodiments of the invention and, together with the general description of the invention given above and the detailed description of the embodiments given below, serve to explain the principles of the invention.

[0056] These and other features of the invention will become apparent from the following description of preferred forms of embodiments given as non-limiting examples, with reference to the accompanying drawings.

[0057] It should also be understood that although the invention has been described with reference to some specific examples, those skilled in the art can certainly implement many other equivalent forms of the invention.

[0058] The above and other aspects, features and advantages of the invention will become more apparent when taken in conjunction with the accompanying drawings and in view of the following detailed description.

[0059] Specific embodiments of the invention are described below with reference to the accompanying drawings; however, it should be understood that the embodiments described are merely examples of the invention, which can be implemented in various ways. Well-known and / or repeated functions and structures are not described in detail to avoid unnecessary or redundant details that could obscure the invention. Therefore, the specific structural and functional details of the invention described herein are not intended to be limiting, but merely to serve as the basis and representative basis for the claims to teach those skilled in the art to use the invention in various ways with substantially any suitable detailed structure.

[0060] This specification may use the phrases “in one embodiment,” “in another embodiment,” “in yet another embodiment,” or “in other embodiments,” all of which may refer to one or more of the same or different embodiments of the present invention.

[0061] This disclosure provides a data processing method based on IP address ranges, such as... Figure 1 As shown, the data processing method based on IP address range includes steps S101 to S105.

[0062] Step S101: Obtain the first IP address range.

[0063] Specifically, the aforementioned first IP address range may include multiple consecutive IP addresses, which can be understood as addresses with the same attributes. For example, all IP addresses within the first IP address range can be understood as addresses that are not allowed to access the website, i.e., addresses with blacklist attributes; or all IP addresses within the first IP address range can be understood as addresses that are allowed to access the website, i.e., addresses with whitelist attributes. The following explanation uses the example of all IP addresses within the first IP address range having blacklist attributes.

[0064] In some alternative embodiments, such as Figure 2 As shown, the data processing method may further include executing step S201 after step S101. Step S201: Determine whether the first IP address range is valid; if yes, then execute the subsequent step S102; if no, then there is no need to insert the first IP address range into the binary tree.

[0065] Step S102: Determine the common prefix of the starting IP and ending IP of the first IP address range, and the length of the common prefix.

[0066] Step S103: Generate a temporary node based on the common prefix and its length.

[0067] Step S104: Compare the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges.

[0068] Specifically, comparing the temporary node with the target node of the binary tree can be done by comparing whether the temporary node and the target node in the binary tree are equal. If the temporary node and the target node in the binary tree are not equal, the common prefix length of the temporary node can be compared with the common prefix length of the target node in the binary tree.

[0069] Specifically, the target node mentioned above can be understood as a node that is not equal to a temporary node when traversing a binary tree in a level-order traversal.

[0070] Specifically, the target position on the binary tree is related to the position of the target node. For example, the target position is the position of the target node, or the target position is the position of the right child node of the target node, or the target position is the position of the left child node of the target node.

[0071] Step S105: Insert the temporary node into the binary tree at the target position, and store the attribute features of the first IP address range into the temporary node to obtain the updated binary tree.

[0072] Specifically, the attribute characteristics of the aforementioned IP address range may include at least the starting IP, ending IP, and creation time of the IP address range.

[0073] This disclosure obtains a temporary node by determining the common prefix of the starting and ending IPs of the first IP address range, as well as the length of the common prefix. The temporary node is compared with the target node on the binary tree to determine the target position to which the temporary node should be inserted on the binary tree. Then, the temporary node is inserted into the binary tree at the target position to obtain an updated binary tree. The above-mentioned binary tree construction speed is relatively fast, and the binary tree constructed in this way has the advantages of high matching efficiency and accurate matching when matching with received packets, which can effectively reduce the cost of maintaining the network.

[0074] In some embodiments, step S104, comparing the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree, specifically includes:

[0075] If the current node of the binary tree is not equal to the temporary node, then the temporary node is inserted into the binary tree.

[0076] In some alternative embodiments, the data processing method may further include: if the current node of the binary tree is equal to the temporary node, directly exit the insertion step of inserting the temporary node and directly release the temporary node.

[0077] In some embodiments, after determining to insert the temporary node into the binary tree, the method further includes:

[0078] If the common prefix length of the temporary node is less than the common prefix length of the current node, the temporary node is inserted as the parent node of the current node.

[0079] The current node is inserted into the right or left child node of the temporary node based on the length of the common prefix of the temporary node.

[0080] In some embodiments, determining whether the current node is inserted as the right or left child of the temporary node based on the common prefix length of the temporary node specifically includes:

[0081] The length of the common prefix of the temporary node is added to the first value to obtain the value N;

[0082] If the Nth bit of the current node is 1, insert the current node into the right child node of the temporary node;

[0083] If the Nth bit of the current node is 0, insert the current node into the left child node of the temporary node.

[0084] Specifically, the first value mentioned above can be 1.

[0085] For example, if the common prefix length of the ephemeral node is 5 and the first value is 1, then the aforementioned value N is 6. If the 6th bit of the current node is 1, the current node is inserted into the right child node of the ephemeral node; if the 6th bit of the current node is 0, the current node is inserted into the left child node of the ephemeral node.

[0086] In some embodiments, after determining to insert the temporary node into the binary tree, the method further includes:

[0087] If the common prefix length of the temporary node is greater than the common prefix length of the current node, the temporary node is inserted as a child node of the current node.

[0088] The temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node.

[0089] In some embodiments, determining whether the temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node specifically includes:

[0090] Add the length of the common prefix of the current node to the first value to obtain the value M;

[0091] If the Mth bit of the temporary node is 1, the temporary node is inserted into the right child node of the current node;

[0092] If the Mth bit of the temporary node is 0, the temporary node is inserted into the left child node of the current node.

[0093] For example, if the common prefix length of the current node is 6 and the first value is 1, then the aforementioned value M is 7. If the 7th bit of the ephemeral node is 1, the ephemeral node is inserted into the right child node of the current node; if the 7th bit of the ephemeral node is 0, the ephemeral node is inserted into the left child node of the current node.

[0094] In some embodiments, such as Figure 3 As shown, the method further includes steps S301 to S304.

[0095] Step S301: Obtain the target IP address corresponding to the received message.

[0096] Step S302: Determine the public prefix and public prefix length of the target IP address.

[0097] Step S303: Starting from the root node of the updated binary tree, perform a level-order traversal and compare the current node of the binary tree with the target IP address.

[0098] Step S304: Determine the matching result of the target IP address with the IP address range stored in the current node of the binary tree based on the comparison result between the current node of the binary tree and the target IP address.

[0099] Thus, by executing steps S301 to S304, the message can be quickly matched with the current node on the binary tree. This method has the advantages of high matching efficiency and high accuracy, and can effectively reduce the cost of maintaining the network.

[0100] Specifically, the public prefix of the target IP address is the IP address itself, and the length of the public prefix is ​​the length of the IP address.

[0101] Specifically, the current node mentioned above is a node in a binary tree. The target IP address is compared with each node in the binary tree. If it does not match the current node, the binary tree is traversed level by level to determine the next node in the binary tree that matches the target IP address. This process continues until the target IP address matches a node in the binary tree. If a match is found, the target IP address is determined to be an address with blacklist attributes, and therefore the packet is intercepted upon successful matching. If the target IP address does not match any node in the binary tree, the matching is considered a failure, and the packet does not need to be intercepted.

[0102] In some embodiments, step S304: determining the matching result between the target IP address and the IP address range stored in at least one node of the binary tree based on the comparison result between the current node of the binary tree and the target IP address specifically includes:

[0103] If the common prefix length of the current node of the binary tree is less than or equal to the common prefix length of the target IP address, determine whether the common prefix length of the current node of the binary tree and the common prefix length of the target IP address are equal.

[0104] If so, generate a matching result indicating successful prefix matching, and match the target IP address with the IP address range;

[0105] If not, then generate a match result where the prefix match failed.

[0106] In some embodiments, matching the target IP address with the IP address range specifically includes:

[0107] Determine whether the IP address range includes the target IP address;

[0108] If so, generate a matching result where the target IP address matches the current node;

[0109] If not, generate a matching result indicating that the target IP address and the current node failed to match, and compare the target IP address with the right or left child node of the current node in the binary tree.

[0110] In some embodiments, comparing the target IP address with the right or left child node of the current node in the binary tree specifically includes:

[0111] The value G is obtained by adding the length of the common prefix of the current node of the binary tree to the first value;

[0112] If the G-th bit of the target IP address is 1, compare the target IP address with the right child node of the current node;

[0113] If the G-th bit of the target IP address is 0, compare the target IP address with the left child node of the current node.

[0114] This disclosure also provides a data processing device 100 based on an IP address range, such as... Figure 4As shown, the data processing device 100 based on IP address range includes an acquisition module 101, a determination module 102, a generation module 103, a comparison module 104, and an insertion module 105. The acquisition module 101 is configured to acquire a first IP address range. The determination module 102 is configured to determine the common prefix of the starting and ending IP addresses of the first IP address range, and the length of the common prefix. The generation module 103 is configured to generate a temporary node based on the common prefix and its length. The comparison module 104 is configured to compare the temporary node with a target node of a binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges. The insertion module 105 is configured to insert the temporary node into the binary tree at the target position and store the attribute characteristics of the first IP address range into the temporary node to obtain an updated binary tree.

[0115] In some embodiments, the comparison module 104 is further configured to: determine to insert the temporary node into the binary tree if the current node of the binary tree is not equal to the temporary node.

[0116] In some embodiments, the comparison module 104 is further configured to: after determining that the temporary node should be inserted into the binary tree, if the common prefix length of the temporary node is less than the common prefix length of the current node, insert the temporary node as the parent node of the current node; and determine whether the current node should be inserted as the right child node or the left child node of the temporary node based on the common prefix length of the temporary node.

[0117] In some embodiments, the comparison module 104 is further configured to:

[0118] The length of the common prefix of the temporary node is added to the first value to obtain the value N;

[0119] If the Nth bit of the current node is 1, insert the current node into the right child node of the temporary node;

[0120] If the Nth bit of the current node is 0, insert the current node into the left child node of the temporary node.

[0121] In some embodiments, the comparison module 104 is further configured to: after determining that the temporary node should be inserted into the binary tree, if the common prefix length of the temporary node is greater than the common prefix length of the current node, insert the temporary node as a child node of the current node;

[0122] The temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node.

[0123] In some embodiments, the comparison module 104 is further configured to:

[0124] Add the length of the common prefix of the current node to the first value to obtain the value M;

[0125] If the Mth bit of the temporary node is 1, the temporary node is inserted into the right child node of the current node;

[0126] If the Mth bit of the temporary node is 0, the temporary node is inserted into the left child node of the current node.

[0127] In some embodiments, the acquisition module 101 is further configured to acquire the target IP address corresponding to the received message; the determination module 102 is further configured to determine the common prefix and common prefix length of the target IP address; the comparison module 104 is further configured to perform a level-wise traversal starting from the root node of the updated binary tree and compare the current node of the binary tree with the target IP address; the determination module 102 is further configured to determine the matching result of the target IP address with the IP address range stored in at least one node of the binary tree based on the comparison result of the current node of the binary tree and the target IP address.

[0128] In some embodiments, the determining module 102 is further configured to:

[0129] If the common prefix length of the current node of the binary tree is less than or equal to the common prefix length of the target IP address, determine whether the common prefix length of the current node of the binary tree and the common prefix length of the target IP address are equal.

[0130] If so, generate a matching result indicating successful prefix matching, and match the target IP address with the IP address range;

[0131] If not, then generate a match result where the prefix match failed.

[0132] In some embodiments, the determining module 102 is further configured to:

[0133] Determine whether the IP address range includes the target IP address;

[0134] If so, generate a matching result where the target IP address matches the current node;

[0135] If not, generate a matching result indicating that the target IP address and the current node failed to match, and compare the target IP address with the right or left child node of the current node in the binary tree.

[0136] Note that the various units in the embodiments of this application can be implemented as computer-executable instructions stored in memory, which, when executed by a processor, can perform corresponding steps; they can also be implemented as hardware with corresponding logical computing capabilities; or they can be implemented as a combination of software and hardware (firmware). In some embodiments, the processor can be implemented as any of an FPGA, ASIC, DSP chip, SOC (System-on-a-Chip), MPU (e.g., but not limited to Cortex), etc. The processor can be communicatively coupled to the memory and configured to execute computer-executable instructions stored therein. The memory can include read-only memory (ROM), flash memory, random access memory (RAM), dynamic random access memory (DRAM) such as synchronous DRAM (SDRAM) or Rambus DRAM, static memory (e.g., flash memory, static random access memory), etc., on which computer-executable instructions are stored in any format. The computer-executable instructions can be accessed by the processor, read from the ROM or any other suitable storage location, and loaded into the RAM for the processor to execute, to implement the wireless communication methods according to the embodiments of this application.

[0137] It should be noted that in the system of this application, the components are logically divided according to the functions they are to perform. However, this application is not limited to this and can re-divide or combine the components as needed. For example, some components can be combined into a single component, or some components can be further decomposed into more sub-components.

[0138] The various component embodiments of this application can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some or all of the components in the system according to the embodiments of this application. This application can also be implemented as a device or apparatus program (e.g., a computer program and computer program product) for performing part or all of the methods described herein. Such a program implementing this application can be stored on a computer-readable medium or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form. Furthermore, this application can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names.

[0139] Furthermore, although exemplary embodiments have been described herein, their scope includes any and all embodiments based on this application that have equivalent elements, modifications, omissions, combinations (e.g., schemes involving intersections of various embodiments), adaptations, or alterations. Elements in the claims will be interpreted broadly based on the language used in the claims and are not limited to the examples described in this specification or during the implementation of this application, which will be interpreted as non-exclusive. Therefore, this specification and examples are intended to be considered illustrative only, and the true scope and spirit are indicated by the full scope of the following claims and their equivalents.

[0140] The above description is intended to be illustrative and not restrictive. For example, the above examples (or one or more of them) can be used in combination with each other. Other embodiments can be used by those skilled in the art when reading the above description. Furthermore, in the above detailed description, various features may be grouped together to simplify the application. This should not be construed as an intention that a disclosed feature not claimed is necessary for any claim. Rather, the subject matter of the application may be less than all the features of a particular disclosed embodiment. Thus, the following claims are incorporated herein by reference as examples or embodiments, wherein each claim is an independent, separate embodiment, and these embodiments are contemplated to be combined with each other in various combinations or arrangements. The scope of this application should be determined by reference to the appended claims and the full scope of their equivalents.

[0141] The above embodiments are merely exemplary embodiments of this application and are not intended to limit this application. The scope of protection of this application is defined by the claims. Those skilled in the art can make various modifications or equivalent substitutions to this application within its substance and scope of protection, and such modifications or equivalent substitutions should also be considered to fall within the scope of protection of this application.

Claims

1. A data processing method based on IP address range, characterized in that, include: Obtain a first IP address range; wherein the first IP address range includes multiple consecutive IP addresses, and the multiple IP addresses in the first IP address range are addresses with the same attributes; Determine the common prefix of the starting and ending IP addresses of the first IP address range, as well as the length of the common prefix; A temporary node is generated based on the common prefix and its length; The temporary node is compared with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein, the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges; the attribute characteristics of the IP address range include at least the starting IP, ending IP, and creation time of the IP address range; the target node is the node that is not equal to the temporary node when the binary tree is traversed in a level-order manner; the target position on the binary tree is related to the position of the target node; the comparison between the temporary node and the target node of the binary tree specifically compares whether the temporary node and the target node on the binary tree are equal; The temporary node is inserted into the binary tree at the target position, and the attribute characteristics of the first IP address range are stored in the temporary node to obtain the updated binary tree; wherein, The method further includes: Obtain the target IP address corresponding to the received message; Determine the common prefix and common prefix length of the target IP address; Starting from the root node of the updated binary tree, perform a level-order traversal and compare the current node of the binary tree with the target IP address; The matching result of the target IP address with the IP address range stored in the current node of the binary tree is determined based on the comparison result between the current node of the binary tree and the target IP address, which includes: If the common prefix length of the current node of the binary tree is less than or equal to the common prefix length of the target IP address, determine whether the common prefix length of the current node of the binary tree and the common prefix length of the target IP address are equal. If so, generate a matching result indicating successful prefix matching, and match the target IP address with the IP address range; If not, then generate a match result where the prefix match failed.

2. The data processing method based on IP address range according to claim 1, characterized in that, The step of comparing the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted in the binary tree specifically includes: If the current node of the binary tree is not equal to the temporary node, then the temporary node is inserted into the binary tree.

3. The data processing method based on IP address range according to claim 2, characterized in that, After determining to insert the temporary node into the binary tree, the method further includes: If the common prefix length of the temporary node is less than the common prefix length of the current node, the temporary node is inserted as the parent node of the current node. The current node is inserted into the right or left child node of the temporary node based on the length of the common prefix of the temporary node.

4. The data processing method based on IP address range according to claim 3, characterized in that, The step of determining whether the current node is inserted as the right or left child of the temporary node based on the common prefix length of the temporary node specifically includes: The length of the common prefix of the temporary node is added to the first value to obtain the value N; If the Nth bit of the current node is 1, insert the current node into the right child node of the temporary node; If the Nth bit of the current node is 0, insert the current node into the left child node of the temporary node.

5. The data processing method based on IP address range according to claim 2, characterized in that, After determining to insert the temporary node into the binary tree, the method further includes: If the common prefix length of the temporary node is greater than the common prefix length of the current node, the temporary node is inserted as a child node of the current node. The temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node.

6. The data processing method based on IP address range according to claim 5, characterized in that, The temporary node is inserted into the right or left child node of the current node based on the length of the common prefix of the current node, specifically including: Add the length of the common prefix of the current node to the first value to obtain the value M; If the Mth bit of the temporary node is 1, the temporary node is inserted into the right child node of the current node; If the Mth bit of the temporary node is 0, the temporary node is inserted into the left child node of the current node.

7. The data processing method based on IP address range according to claim 1, characterized in that, The matching of the target IP address with the IP address range specifically includes: Determine whether the IP address range includes the target IP address; If so, generate a matching result where the target IP address matches the current node; If not, generate a matching result indicating that the target IP address and the current node failed to match, and compare the target IP address with the right or left child node of the current node in the binary tree.

8. A data processing device based on an IP address range, characterized in that, To implement the method as described in claim 1, comprising: The acquisition module is configured to acquire the first IP address range. The determining module is configured to determine the common prefix of the start and end IPs of the first IP address range, and the length of the common prefix; A generation module, configured to generate temporary nodes based on the common prefix and its length; A comparison module is configured to compare the temporary node with the target node of the binary tree to determine the target position where the temporary node should be inserted into the binary tree; wherein the binary tree includes at least multiple nodes storing attribute characteristics of different IP address ranges; An insertion module is configured to insert the temporary node into the binary tree at the target position and store the attribute features of the first IP address range into the temporary node to obtain an updated binary tree.

Citation Information

Patent Citations

  • IP address ownership information indexing and fast querying method

    CN103561133A