IP address query method, device and storage medium
By adjusting the preset field values and the number of hosts in the IP address, generating a network number and querying the database, the problem of high computing power consumption caused by hash table construction in the existing technology is solved, and fast, low-computing-power IP address tracing query is achieved.
Patent Information
- Application Number
- CN202310520487.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-09
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2043-05-09
AI Technical Summary
In the existing technology, IP address tracing queries require the construction of a large number of hash matching tables, resulting in excessive consumption of computing resources and cannot be applied to the actual operating scenarios of basic telecommunications operators and Internet service providers.
By obtaining the value of the preset field of the IP address to be queried and the number of hosts, the number of queries is determined, and the value of the preset field is iteratively adjusted within the query number to generate a network number, and the database is queried to determine the ownership information, thereby avoiding hash operations and hash table construction.
It realizes fast and low-computing-power IP address tracing query, reduces computational complexity, and is suitable for the actual needs of basic telecommunications operators and Internet service providers.
Smart Images

Figure CN116668399B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to an IP address query method, device, and storage medium. Background Art
[0002] Currently, the method for tracing the origin of an Internet Protocol (IP) address is to obtain the hash value of the host address portion of the IP address to match the relevant information of the IP address to be queried. However, this query method requires the construction of a large number of hash matching tables based on the type of IP address, resulting in a large amount of computing power required for tracing the origin of the IP address. Therefore, how to trace the origin of the IP address to be queried through fast calculation has become a technical problem that needs to be solved urgently. Summary of the Invention
[0003] The present application provides an IP address query method, device and storage medium, which can query IP addresses.
[0004] To achieve the above objectives, this application adopts the following technical solutions:
[0005] In a first aspect, the present application provides a method for querying an Internet Protocol (IP) address, the method comprising: obtaining a value of a preset field of an IP address to be queried and the number of hosts for the IP address to be queried; assuming the field includes at least one of the following: a first preset field and a second preset field, the second preset field being a field in the IP address to be queried that is different from the first preset field; determining a number of queries for the IP address to be queried based on the value of the preset field and the number of hosts; iteratively performing a target operation within the number of queries to determine attribution information for the IP address to be queried; the target operation being used to adjust the value of the preset field, and determining the attribution information of the network number obtained after the field adjustment as the attribution information for the IP address to be queried. In combination with the first aspect above, in a possible implementation method, within the query number, iteratively executing the target operation to determine the ownership information of the IP address to be queried includes: step 1, adjusting the value of the preset field of the IP address to be queried to determine the network number of the IP address to be queried; step 2, querying the database whether the ownership information of the IP address in the network number exists; step 3, if so, determining the ownership information of the IP address in the network number as the ownership information of the IP address to be queried, and ending the iteration; step 4, if not, iteratively executing steps 1, 2, 3 and 4 until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the query number; ending the iteration.
[0006] In combination with the above-mentioned first aspect, in a possible implementation method, the IP address to be queried is an IP address of the first type; querying whether the ownership information of the IP address in the network number exists in the database, including: determining multiple subnet masks in different network bits of a preset field; generating a target regular expression based on the network number and multiple subnet masks; the target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks; based on the target regular expression, querying whether the ownership information of the IP address in the network number exists in the database.
[0007] In combination with the above-mentioned first aspect, in a possible implementation method, based on a regular expression, a query is made in the database as to whether the ownership information of the IP address in the network number exists, including: step a, determining the first target IP address generated by the network number and the first subnet mask according to the target regular expression; the first subnet mask is a subnet mask that has not been queried among multiple subnet masks; step b, querying the database as to whether the ownership information of the first target IP address exists; step c, if the information of the target IP address exists, returning the information of the target IP address; step d, if the information of the first target IP address does not exist, executing the above steps 1 to 3 until the information of the target IP address is returned, or multiple subnet masks are all queried.
[0008] In conjunction with the first aspect above, in one possible implementation, the target regular expression includes: a first target regular expression or a second target regular expression; wherein the network number in the first target regular expression is: the value of the first preset field is adjusted to the difference between the first preset field and a first remainder; the first remainder is the remainder obtained by dividing the value of the first preset field by the number of hosts; and the network number in the second target regular expression is: the value of the second preset field is adjusted to the difference between the second preset field and the second remainder. Furthermore, the first preset field is replaced with a fixed value; the second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts; the fixed value is a natural number.
[0009] In a second aspect, the present application provides an Internet Protocol (IP) address query device, comprising: a processing unit; the processing unit is configured to obtain a value of a preset field of the IP address to be queried and the number of hosts for the IP address to be queried; the preset field includes at least one of the following: a first preset field and a second preset field, the second preset field being a field in the IP address to be queried that is different from the first preset field. The processing unit is further configured to determine a query count for the IP address to be queried based on the value of the preset field and the number of hosts; the processing unit is further configured to iteratively perform a target operation within the query count to determine the attribution information of the IP address to be queried; the target operation is configured to adjust the value of the preset field and determine the attribution information of the network number obtained after the field adjustment as the attribution information of the IP address to be queried.
[0010] In combination with the above-mentioned second aspect, in a possible implementation method, the processing unit is specifically used to: Step 1, adjust the value of the preset field of the IP address to be queried, and determine the network number of the IP address to be queried; Step 2, query whether the ownership information of the IP address in the network number exists in the database; Step 3, if it exists, determine the ownership information of the IP address in the network number as the ownership information of the IP address to be queried, and end the iteration; Step 4, if it does not exist, iteratively execute Step 1, Step 2, Step 3 and Step 4 until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the query number; end the iteration.
[0011] In combination with the above-mentioned second aspect, in a possible implementation method, the processing unit is also specifically used to: determine multiple subnet masks of the preset field in different network bits; generate a target regular expression based on the network number and multiple subnet masks; the target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks; based on the target regular expression, query whether the ownership information of the IP address in the network number exists in the database.
[0012] In combination with the above-mentioned second aspect, in a possible implementation method, the processing unit is further specifically used to: step a, determine the first target IP address generated by the network number and the first subnet mask according to the target regular expression; the first subnet mask is a subnet mask that has not been queried among multiple subnet masks; step b, query the database whether there is attribution information of the first target IP address; step c, if there is information about the target IP address, return the information of the target IP address; step d, if there is no information about the first target IP address, execute the above steps 1-step 3 until the information of the target IP address is returned, or multiple subnet masks are queried.
[0013] In conjunction with the second aspect, in one possible implementation, the target regular expression includes: a first target regular expression or a second target regular expression; wherein the network number in the first target regular expression is: the value of the first preset field is adjusted to the difference between the first preset field and a first remainder; the first remainder is the remainder obtained by dividing the value of the first preset field by the number of hosts; and the network number in the second target regular expression is: the value of the second preset field is adjusted to the difference between the second preset field and the second remainder. Furthermore, the first preset field is replaced with a fixed value; the second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts; the fixed value is a natural number.
[0014] In a third aspect, the present application provides an IP address query device, which includes: a processor and a memory; wherein the memory is used to store computer-executable instructions, and when the IP address query device is running, the processor executes the computer-executable instructions stored in the memory, so that the IP address query device performs the IP address query method described in the first aspect and any possible implementation of the first aspect.
[0015] In a fourth aspect, the present application provides a computer-readable storage medium, which stores instructions. When the instructions in the computer-readable storage medium are executed by the processor of the IP address query device, the IP address query device is able to perform the IP address query method described in the first aspect and any possible implementation of the first aspect.
[0016] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when run on an IP address query device, enables the IP address query device to perform the IP address query method as described in the first aspect and any possible implementation of the first aspect.
[0017] In a sixth aspect, the present application provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the IP address query method described in the first aspect and any possible implementation of the first aspect.
[0018] Specifically, the chip provided in the embodiment of the present application also includes a memory for storing computer programs or instructions.
[0019] In this application, the name of the IP address query device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of this application, they fall within the scope of the claims of this application and their equivalents.
[0020] These and other aspects of the present application will become more readily apparent from the following description.
[0021] The technical solution provided by the present application brings at least the following beneficial effects: the IP address query device obtains the value of the preset field of the IP address to be queried and the number of hosts of the IP address to be queried. The IP address query device determines the number of queries for the IP address to be queried based on the value of the preset field and the number of hosts. Within the number of queries, the IP address query device obtains the network number by adjusting the value of the preset field. Within the number of queries, the IP address query device iteratively adjusts the value of the preset field, and queries the database for the ownership information of the network number based on the network number obtained after adjusting the field value. The IP address query device queries the ownership information of the network number and determines that the ownership information is the ownership information of the IP address to be queried. In this way, the IP address query device obtains the network number of the IP address to be queried only by adjusting the preset field of the IP address to be queried, and then determines the ownership information of the IP address to be queried based on the obtained network number. There is no need to perform hash operations on the IP address to be queried and to construct a large number of hash tables, thus solving the technical problem of tracing the IP address to be queried through quick calculations. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A schematic diagram of the hardware structure of an IP address query device provided in an embodiment of the present application;
[0023] Figure 2 A flowchart of a method for querying an IP address provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of another method for querying an IP address provided in an embodiment of the present application is provided;
[0025] Figure 4 A flowchart of another method for querying an IP address provided in an embodiment of the present application is provided;
[0026] Figure 5 A schematic diagram of an IP address query device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] The IP address query method, device and storage medium provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0028] The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0029] The terms "first" and "second" and the like in the specification and drawings of this application are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of objects.
[0030] Furthermore, the terms "including," "having," and any variations thereof, as used in the description of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not limited to the listed steps or units, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to the process, method, product, or apparatus.
[0031] It should be noted that in the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being more preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0032] In the related art, the method for tracing the source of an IP address is to match the relevant information of the IP address to be queried by obtaining the hash value of the host address portion of the IP address to be queried. However, this query method requires the construction of a large number of hash matching tables based on the type of the IP address. Specifically, the IP address tracing device determines the address type of the IP address to be queried based on the network address portion of the IP address, and calculates the hash value based on the host address portion of the IP address. The IP address tracing device constructs a Class A hash table, a Class B hash table, a Class C hash table, a Class D hash table, and a Class E hash table based on the five types of IP addresses. Furthermore, the IP address tracing device matches the obtained hash values with the above-constructed hash tables one by one. As a result, the tracing of the source of an IP address requires a large amount of computing power resources and cannot be applied to the actual operation scenarios of Internet access units such as basic telecommunications operators, Internet Service Providers (ISPs), and Internet Data Centers (IDCs). Therefore, how to trace the source of the IP address to be queried through quick calculations has become a technical problem that needs to be solved urgently.
[0033] To address the above-mentioned technical problems, the present application provides an IP address query method, in which an IP address query device obtains the value of a preset field of the IP address to be queried and the number of hosts for the IP address to be queried. The IP address query device determines the number of queries for the IP address to be queried based on the value of the preset field and the number of hosts. Within the query number, the IP address query device obtains a network number by adjusting the value of the preset field. Within the query number, the IP address query device iteratively adjusts the value of the preset field and, based on the network number obtained after adjusting the field value, queries a database for the network number's ownership information. The IP address query device queries the network number's ownership information and determines that the ownership information is the ownership information for the IP address to be queried. In this way, the IP address query device obtains the network number of the IP address to be queried simply by adjusting the preset field of the IP address to be queried, and then determines the ownership information of the IP address to be queried based on the obtained network number. This eliminates the need to perform a hash operation on the IP address to be queried and construct a large number of hash tables, thereby solving the technical problem of tracing the IP address to be queried through quick calculations.
[0034] Figure 1 This is a schematic diagram of the structure of an IP address query device provided in an embodiment of the present application. The IP address query device 100 includes at least one processor 101, a communication line 102, and at least one communication interface 104. It may also include a memory 103. The processor 101, the memory 103, and the communication interface 104 can be connected via the communication line 102.
[0035] The processor 101 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application, such as one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs).
[0036] The communication link 102 may include a pathway for transmitting information between the aforementioned components.
[0037] The communication interface 104 is used to communicate with other devices or communication networks and can use any transceiver-like device, such as Ethernet, radio access network (RAN), wireless local area network (WLAN), etc.
[0038] The memory 103 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to include or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0039] In one possible design, memory 103 can exist independently of processor 101, that is, memory 103 can be a memory external to processor 101. In this case, memory 103 can be connected to processor 101 via communication line 102 to store execution instructions or application code, and processor 101 controls execution to implement the spatial measurement determination method provided in the following embodiments of this application. In another possible design, memory 103 can also be integrated with processor 101, that is, memory 103 can be internal memory of processor 101. For example, memory 103 is a cache that can be used to temporarily store some data and instruction information.
[0040] As a possible implementation, the processor 101 may include one or more CPUs, such as Figure 1 As another implementation method, the IP address query device 100 may include multiple processors, such as Figure 1 As another implementation, the IP address query apparatus 100 may further include an output device 105 and an input device 106.
[0041] Through the description of the above embodiments, those skilled in the art will clearly understand that for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the network node can be divided into different functional modules to complete all or part of the functions described above. The specific working processes of the above-described systems, modules, and network nodes can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0042] Figure 2 The IP address query method provided in the embodiment of the present application is as follows: Figure 2 As shown, the IP address query method provided in the embodiment of the present application can be implemented through the following steps 201 to 203.
[0043] Step 201: The IP address query device obtains the value of the preset field of the IP address to be queried and the number of hosts of the IP address to be queried.
[0044] The preset field includes at least one of the following: a first preset field and a second preset field, and the second preset field is a field in the IP address to be queried that is different from the first preset field.
[0045] In a possible implementation, the IP address to be queried is abcd, and the IP address query device obtains the first preset field d or the second preset field c of the IP address to be queried. The IP address query device determines the number of hosts of the IP address to be queried according to the subnet mask of the IP address to be queried.
[0046] In one example, if the IP address to be queried is 2*1.2*.1*6.221 / 29, the value of the first preset field of the IP address to be queried is 221, and the value of the second preset field is 126. The IP address query device determines that the number of hosts of the IP address to be queried is 2 based on the subnet mask of the IP address to be queried being 29. 3 That is, the number of hosts whose IP addresses are to be queried is 8.
[0047] Optionally, if the IP address to be queried is 2*1.2*.1*6.221 / 30, the value of the preset field of the IP address to be queried is 221. The IP address query device determines that the number of hosts of the IP address to be queried is 2 based on the subnet mask of the IP address to be queried being 30. 2 That is, the number of hosts whose IP addresses are to be queried is 4.
[0048] Step 202: The IP address query device determines the query times for the IP address to be queried according to the value of the preset field and the number of hosts.
[0049] In one possible implementation, the IP address query device determines a divisor between the value of the preset field and the number of hosts by dividing the obtained value of the preset field by the number of hosts whose IP address is to be queried. The divisor determined by the IP address query device is the number of queries for the IP address to be queried.
[0050] In one example, the IP address to be queried is 2*1.2*.1*6.221 / 29, where the subnet mask of the IP address to be queried is 29. Therefore, the number of hosts for which the IP address to be queried is 8. The value of the preset field obtained by the IP address query device is 221. The preset number of queries determined is 221 divided by 8, i.e., the number of queries for the IP address to be queried is 27.
[0051] Step 203: The IP address query device iteratively performs the target operation within the query times to determine the ownership information of the IP address to be queried.
[0052] The target operation is used to adjust the value of a preset field, and determine the ownership information of the network number obtained after the field adjustment as the ownership information of the IP address to be queried.
[0053] In one possible implementation, when the IP address query device cannot obtain the attribution information of the IP address to be queried based on the IP address to be queried, the IP address query device adjusts the value of a preset field within a query count to obtain the network number of the IP address to be queried. The IP address query device iteratively performs the target operation within the query count based on the obtained network number to determine the attribution information of the IP address to be queried.
[0054] In one example, an IP address query device determines the network number of the IP address to be queried. The process for determining the network number of the IP address to be queried is as follows: For example, taking the IP address to be queried as 2*1.2*.1*6.221 / 29, the IP address query device obtains the remainder of dividing the value of the preset field of the IP address to be queried, 221, by the number of hosts of the IP address to be queried, 8, which is 5. The IP address query device adjusts the value of the preset field of the IP address to be queried, for example, by subtracting the remainder 5 from the value of the preset field, 221, to obtain the network number of the IP address to be queried: 2*1.2*.1*6.216.
[0055] Furthermore, the IP address query device queries a database based on the obtained network number to determine whether there is attribution information for the IP address in the network number. If there is attribution information for the IP address in the network number, the IP address query device returns the relevant attribution information. If there is no attribution information for the IP address in the network number, the IP address query device performs the following target operation within the query count: the IP address query device adjusts the value of a preset field in the network number of the IP address to be queried.
[0056] Specifically, if the IP address to be queried is 2*1.2*.1*6.221 / 29, then the network number of the IP address to be queried is: 2*1.2*.1*6.216. The IP address query device adjusts the value of the preset field in the network number to the difference between the value 216 of the preset field and the value 8, that is, 2*1.2*.1*6.208 / 29. Correspondingly, the network number is: 2*1.2*.1*6.208; the IP address query device continues to query whether there is the ownership information of the IP address in the network number based on the new network number. If not, the IP address query device continues to iteratively perform the target operation within the query number, until the iteration is terminated when the ownership information of the IP address to be queried is determined, or when the number of iterations reaches the query number, the query is terminated.
[0057] Alternatively, if the IP address to be queried is 2*1.2*.1*6.221 / 30, the network number of the IP address to be queried is: 2*1.2*.1*6.216. The IP address query device adjusts the value of the preset field in the network number to the sum of the value of the preset field 216 and the value 1, that is, 2*1.2*.1*6.217 / 30.
[0058] The above solution brings at least the following beneficial effects: the IP address query device obtains the value of the preset field of the IP address to be queried and the number of hosts of the IP address to be queried. The IP address query device determines the number of queries for the IP address to be queried based on the value of the preset field and the number of hosts. Within the query number, the IP address query device obtains the network number by adjusting the value of the preset field. Within the query number, the IP address query device iteratively adjusts the value of the preset field and queries the database for the ownership information of the network number based on the network number obtained after adjusting the field value. The IP address query device queries the ownership information of the network number and determines that the ownership information is the ownership information of the IP address to be queried. In this way, the IP address query device obtains the network number of the IP address to be queried only by adjusting the preset field of the IP address to be queried, and then determines the ownership information of the IP address to be queried based on the obtained network number. There is no need to perform hash operations on the IP address to be queried and to construct a large number of hash tables, thus solving the technical problem of tracing the source of the IP address to be queried through quick calculations.
[0059] In one possible implementation, step 203, i.e., the IP address query device iteratively performs the target operation within the query times to determine the ownership information of the IP address to be queried, can be specifically implemented in the following manner:
[0060] In one example, the IP address query device iteratively performs the target operation within the query coefficient to determine the ownership information of the IP address to be queried, which can be achieved by following steps 1 to 4:
[0061] Step 1: The IP address query device adjusts the value of the preset field of the IP address to be queried to determine the network number of the IP address to be queried.
[0062] Step 2: The IP address query device queries the database to see whether there is ownership information of the IP address in the network number.
[0063] Step 3: If the ownership information of the IP address in the network number exists, the IP address query device determines the ownership information of the IP address in the network number as the ownership information of the IP address to be queried, and ends the iteration.
[0064] Step 4: If the ownership information of the IP address in the network number does not exist, the IP address query device iteratively executes steps 1, 2, 3 and 4 until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the query number; the iteration ends.
[0065] Combine Figure 2 ,like Figure 3 As shown, if the IP address to be queried is an IP address of the first type, the process of the IP address query device querying whether there is attribution information of the IP address in the network number in the database can be implemented by the following steps 301-303:
[0066] Step 301: The IP address query device determines multiple subnet masks with preset fields at different network positions.
[0067] In a possible implementation, the IP address query device determines multiple subnet masks of the network bits of the IP address to be queried in the first preset field, or multiple subnet masks of the network bits in the second preset field.
[0068] It should be noted that the first type of IP address refers to an IP address with a subnet mask of 29.
[0069] In one example, the IP address query device determines that the multiple subnet masks of different network bits corresponding to the first preset field "221" of the IP address to be queried 201*.21*.126.221 / 29 are: 25, 26, 27, 28, 29; the multiple subnet masks of different network bits corresponding to the second preset field "126" of the IP address to be queried 2*1.2*.126.221 / 29 are: 17, 18, 19, 20, 21, 22, 23, 24.
[0070] Step 302: The IP address query device generates a target regular expression according to the network number and multiple subnet masks.
[0071] The target regular expression includes: a first target regular expression or a second target regular expression.
[0072] In one possible implementation, if the IP address query device cannot find relevant attribution information for the queried IP address in the database based on the queried IP address, the IP address query device generates a target regular expression based on the network number of the queried IP address and multiple subnet masks corresponding to different network bits in a preset field. The target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks.
[0073] In one example, if the IP address query device fails to find the IP address's attribution information in the database based on the query IP address 2*1.2*.126.221 / 29, the IP address query device constructs a first target regular expression for the query IP address based on the network ID of the IP address and the multiple subnet masks corresponding to different network bits in the preset field. For example, if the network ID of the query IP address is 2*1.2*.126.216, and the subnet masks corresponding to different network bits in the first preset field "216" are 25, 26, 27, 28, and 29, respectively, the regular expression constructed by the IP address query device is 2*1.2*.126.216 / [25-29].
[0074] Furthermore, if the IP address query device fails to find the attribution information of the IP address in the database based on the first target regular expression of the IP address to be queried, the IP address query device replaces the value 221 of the first preset field of the IP address to be queried with 0. At the same time, the IP address query device adjusts the value 126 of the second preset field to the difference between the second preset field and the second remainder. The second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts of the IP address to be queried, that is, the remainder 6 when 126 is divided by 8. In addition, the subnet masks corresponding to the different network bits of the second preset field of the IP address to be queried are: 17, 18, 19, 20, 21, 22, 23, and 24, respectively. The IP address query device then constructs the second target regular expression for the IP address to be queried, that is, 2*1.2*.120.0 / [17-24], based on the network number of the IP address and the multiple subnet masks corresponding to the preset fields at different network bits.
[0075] Step 303: The IP address query device queries the database based on the target regular expression whether there is ownership information of the IP address in the network number.
[0076] In one possible implementation, the IP address query device determines the target IP address based on the constructed regular expression of the IP address to be queried. The IP address query device queries the database for attribution information of the target IP address determined by the network number and subnet mask in the regular expression.
[0077] In one example, if the target regular expression determined by the IP address query device is 2*1.2*.1*6.216 / [25-29], the IP address query device sequentially queries for the relevant attribution information of the target IP addresses corresponding to 2*1.2*.1*6.216 / 25, 2*1.2*.1*6.216 / 26, 2*1.2*.1*6.216 / 27, 2*1.2*.1*6.216 / 28, and 2*1.2*.1*6.216 / 29. If the IP address query device finds that the attribution information of the target IP address exists in the database during the sequential query process, the IP address query device terminates the query and determines the attribution information of the target IP address as the attribution information of the IP address to be queried and returns it.
[0078] If the IP address query device does not find the attribution information of the target IP address in the database during the query process, the IP address query device performs the above step 203, that is, the IP address query device iteratively performs the target operation within the query number to determine the attribution information of the IP address to be queried. The specific implementation process can be referred to the above step 203 and will not be repeated here.
[0079] The above solution provides at least the following beneficial effects: the IP address query device determines multiple subnet masks for different network locations of a preset field of the IP address to be queried, and generates a target regular expression based on the network number and the multiple subnet masks of the IP address to be queried. The IP address query device then queries the database based on the regular expression to determine whether the IP address corresponding to the network number has ownership information. In this way, the IP address query device can determine the ownership information of the IP address to be queried simply by determining the ownership information of the IP address in different network segments, without having to construct a hash table, thereby reducing the computational complexity of querying the IP address.
[0080] In one example, based on a target regular expression, a process of querying whether the ownership information of the IP address in the network number exists in the database can be specifically implemented by following steps a to d:
[0081] Step a: The IP address query device determines the first target IP address generated by the network number and the first subnet mask according to the target regular expression; the first subnet mask is a subnet mask that has not been queried among the multiple subnet masks.
[0082] Step b: The IP address query device queries the database to see whether there is attribution information of the first target IP address.
[0083] Step c: If the target IP address information exists, the IP address query device returns the target IP address information.
[0084] Step d: If the information of the first target IP address does not exist, the IP address query device executes the above steps 1 to 3 until the information of the target IP address is returned, or multiple subnet masks are queried.
[0085] The following, combined Figure 4 , the overall process of the IP address query device is explained:
[0086] Step 401: The IP address query device receives the IP address to be queried.
[0087] Step 402: The IP address query device determines the type of the IP address to be queried.
[0088] The types of IP addresses to be queried include: first-class IP addresses and second-class IP addresses.
[0089] In one possible implementation, if the subnet mask of the IP address to be queried is 29 bits, the IP address to be queried is a Class I IP address. If the subnet mask of the IP address to be queried is 30 bits, the IP address to be queried is a Class II IP address.
[0090] In one example, the IP address to be queried is 2*1.2*.1*6.216 / 29, which is a first-class IP address; the IP address to be queried is 2*1.2*.1*6.221 / 30, which is a second-class IP address.
[0091] It should be noted that the first type of IP address is the IP address with a subnet mask of 29; the second type of IP address is the IP address with a subnet mask of 30.
[0092] Step 403: If the IP address to be queried does not exist in the database, the IP address query device obtains the value of the preset field of the IP address to be queried and the number of hosts of the IP address to be queried.
[0093] The specific implementation of step 403 is similar to that of step 201 above. The specific implementation process can refer to step 201 and will not be repeated here.
[0094] Step 404: The IP address query device determines the query times for the IP address to be queried according to the value of the preset field and the number of hosts.
[0095] The specific implementation of step 404 is similar to that of step 202 above. The specific implementation process can refer to step 202 and will not be repeated here.
[0096] Step 405: The IP address query device iteratively performs the target operation within the query times to determine the ownership information of the IP address to be queried.
[0097] The specific implementation of step 405 is similar to that of step 203 above. The specific implementation process can refer to step 203 and will not be repeated here.
[0098] It should be noted that the ownership information of the IP address to be queried includes but is not limited to the information contained in Table 1.
[0099] Table 1. Ownership information of the IP address to be queried
[0100]
[0101] Step 406: If the IP address to be queried is a first-class IP address, the IP address query device determines multiple subnet masks with preset fields at different network bits.
[0102] The specific implementation of step 406 is similar to that of step 301 above. The specific implementation process can refer to step 301 and will not be repeated here.
[0103] Step 407: The IP address query device generates a target regular expression according to the network number and multiple subnet masks.
[0104] The specific implementation of step 407 is similar to that of step 302 above. The specific implementation process can refer to step 302 and will not be repeated here.
[0105] Step 408: The IP address query device queries the database based on the target regular expression whether there is ownership information of the IP address in the network number.
[0106] The specific implementation of step 408 is similar to that of step 303 above. The specific implementation process can refer to step 303 and will not be repeated here.
[0107] The above describes in detail the IP address query device involved in the embodiment of the present application, the functions of each device of the IP address query device, and the interaction between the devices.
[0108] It can be seen that the above mainly introduces the technical solutions provided by the embodiments of the present application from the perspective of methods. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the modules and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0109] In the embodiment of the present application, the IP address query device can be divided into functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated modules can be implemented in the form of hardware or software functional modules. Optionally, the division of modules in the embodiment of the present application is schematic and is only a logical functional division. In actual implementation, there may be other division methods.
[0110] The embodiments of the present application provide an IP address query device for executing the method required to be executed by any device in the above-mentioned IP address query system. The IP address query device can be the IP address query device involved in this application, or a module in the IP address query device; or a chip in the IP address query device, or other devices for executing the IP address query method, which are not limited in this application.
[0111] like Figure 5 FIG. 5 is a schematic diagram of the structure of an IP address query device provided by an embodiment of the present application. The IP address query device includes: a processing unit 501 and a communication unit 502.
[0112] Processing unit 501 is configured to obtain a value of a preset field of the IP address to be queried and the number of hosts of the IP address to be queried; the preset field includes at least one of the following: a first preset field and a second preset field, where the second preset field is a field in the IP address to be queried that is different from the first preset field. Processing unit 501 is further configured to determine a query count for the IP address to be queried based on the value of the preset field and the number of hosts; processing unit 501 is further configured to iteratively perform a target operation within the query count to determine the attribution information of the IP address to be queried; the target operation is configured to adjust the value of the preset field and determine the attribution information of the network number obtained after the adjustment as the attribution information of the IP address to be queried.
[0113] Optionally, the processing unit 501 is specifically used to: Step 1, adjust the value of the preset field of the IP address to be queried, and determine the network number of the IP address to be queried; Step 2, query whether the ownership information of the IP address in the network number exists in the database; Step 3, if it exists, determine the ownership information of the IP address in the network number as the ownership information of the IP address to be queried, and end the iteration; Step 4, if it does not exist, iteratively execute Step 1, Step 2, Step 3 and Step 4 until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the number of queries; end the iteration.
[0114] Optionally, the processing unit 501 is also specifically used to: determine multiple subnet masks in different network bits of the preset field; generate a target regular expression based on the network number and multiple subnet masks; the target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks; based on the target regular expression, query whether the ownership information of the IP address in the network number exists in the database.
[0115] Optionally, the processing unit 501 is further specifically used to: step a, determine the first target IP address generated by the network number and the first subnet mask according to the target regular expression; the first subnet mask is a subnet mask that has not been queried among the multiple subnet masks; step b, query whether there is attribution information of the first target IP address in the database; step c, if there is information about the target IP address, return the information of the target IP address; step d, if there is no information about the first target IP address, execute the above steps 1 to 3 until the information of the target IP address is returned, or multiple subnet masks are queried.
[0116] Optionally, the processing unit 501 is further specifically configured to: a target regular expression including a first target regular expression or a second target regular expression; wherein the network number in the first target regular expression is: adjusting the value of the first preset field to the difference between the first preset field and a first remainder; the first remainder is the remainder obtained by dividing the value of the first preset field by the number of hosts; and the network number in the second target regular expression is: adjusting the value of the second preset field to the difference between the second preset field and the second remainder. Furthermore, the first preset field is replaced with a fixed value; the second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts; the fixed value is a natural number.
[0117] The embodiments of the present application provide an IP address query device for executing the method required to be executed by any device in the above-mentioned IP address query system. The IP address query device can be the IP address query device involved in this application, or a module in the IP address query device; or a chip in the IP address query device, or other devices for executing the IP address query method, which are not limited in this application.
[0118] An embodiment of the present application further provides a computer-readable storage medium, in which instructions are stored. When a computer executes the instructions, the computer executes each step in the method flow shown in the above method embodiment.
[0119] An embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the IP address query method in the above method embodiment.
[0120] An embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the IP address query method in the above method embodiment.
[0121] Among them, the computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk. Random Access Memory (RAM), Read-Only Memory (ROM), Erasable Programmable Read Only Memory (EPROM), a register, a hard disk, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any other form of computer-readable storage medium in a suitable combination of the above, or a numerical value in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an application-specific integrated circuit (ASIC). In the embodiments of the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0122] Since the apparatus, equipment, computer-readable storage medium, and computer program product in the embodiments of the present application can be applied to the above-mentioned method, the technical effects that can be obtained can also refer to the above-mentioned method embodiments, and the embodiments of the present application will not be repeated here.
[0123] The above is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or replacements within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A method for querying an Internet Protocol (IP) address, characterized in that: The method comprises: Obtaining a value of a preset field of the IP address to be queried and the number of hosts of the IP address to be queried; the preset field includes at least one of the following: the first preset field and a second preset field, where the second preset field is a field in the IP address to be queried that is different from the first preset field; Determining the number of queries for the IP address to be queried based on the value of the preset field and the number of hosts; Within the query times, the target operation is iteratively executed to determine the ownership information of the IP address to be queried; the target operation is used to adjust the value of the preset field, and the ownership information of the network number obtained after adjusting the field is determined as the ownership information of the IP address to be queried.
2. The method according to claim 1, characterized in that The iteratively performing the target operation within the query number to determine the attribution information of the IP address to be queried includes: Step 1: Adjust the value of the preset field of the IP address to be queried to determine the network number of the IP address to be queried; Step 2: Check the database for the IP address in the network number. Step 3: If the ownership information of the IP address in the network number exists, the ownership information of the IP address in the network number is determined as the ownership information of the IP address to be queried, and the iteration is terminated; Step 4: If the ownership information of the IP address in the network number does not exist, iteratively execute step 1, step 2, step 3 and step 4 until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the number of queries; end the iteration.
3. The method according to claim 2, characterized in that The IP address to be queried is an IP address of the first type; The querying database for whether the ownership information of the IP address in the network number exists includes: Determine multiple subnet masks of the preset field at different network positions; Generate a target regular expression based on the network number and the multiple subnet masks; the target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks; Based on the target regular expression, the database is queried to determine whether the attribution information of the IP address in the network number exists.
4. The method according to claim 3, characterized in that The querying, based on the regular expression, whether the attribution information of the IP address in the network number exists in the database includes: Step a: determining a first target IP address generated by the network number and a first subnet mask according to a target regular expression; the first subnet mask is a subnet mask that has not been queried among the multiple subnet masks; Step b, querying the database to see whether there is attribution information of the first target IP address; Step c: If the target IP address information exists, return the target IP address information; Step d: If the information of the first target IP address does not exist, execute the above steps 1 to 3 until the information of the target IP address is returned or the multiple subnet masks are all queried.
5. The method according to claim 4, characterized in that The target regular expression includes: a first target regular expression or a second target regular expression; The network number in the first target regular expression is: the value of the first preset field is adjusted to the difference between the first preset field and the first remainder; the first remainder is the remainder obtained by dividing the value of the first preset field by the number of hosts; The network number in the second target regular expression is: the value of the second preset field is adjusted to the difference between the second preset field and the second remainder; and the first preset field is replaced with a fixed value; the second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts; the fixed value is a natural number.
6. An Internet Protocol (IP) address query device, characterized in that: The device comprises: a processing unit; The processing unit is configured to obtain a value of a preset field of the IP address to be queried and the number of hosts of the IP address to be queried; the preset field includes at least one of the following: the first preset field and a second preset field, the second preset field being a field in the IP address to be queried that is different from the first preset field; The processing unit is further configured to determine a query count for the IP address to be queried based on the value of the preset field and the number of hosts; The processing unit is also used to iteratively execute the target operation within the query number to determine the ownership information of the IP address to be queried; the target operation is used to adjust the value of the preset field, and determine the ownership information of the network number obtained after the adjustment field as the ownership information of the IP address to be queried.
7. The device according to claim 6, characterized in that The processing unit is specifically configured to: Step 1: Adjust the value of the preset field of the IP address to be queried to determine the network number of the IP address to be queried; Step 2: Check the database for the IP address in the network number. Step 3: If the IP address exists, the ownership information of the IP address in the network number is determined as the ownership information of the IP address to be queried, and the iteration is terminated; Step 4: If it does not exist, iterate and execute step 1, step 2, step 3 and step 4 in a loop until the ownership information of the IP address to be queried is determined, or the number of iterations reaches the number of queries; end the iteration.
8. The device according to claim 7, characterized in that The processing unit is further specifically configured to: Determine multiple subnet masks of the preset field at different network positions; Generate a target regular expression based on the network number and the multiple subnet masks; the target regular expression is used to determine the IP address generated by the network number and any one of the multiple subnet masks; Based on the target regular expression, the database is queried to determine whether the attribution information of the IP address in the network number exists.
9. The device according to claim 8, characterized in that The processing unit is further specifically configured to: Step a: determining a first target IP address generated by the network number and a first subnet mask according to a target regular expression; the first subnet mask is a subnet mask that has not been queried among the multiple subnet masks; Step b, querying the database to see whether there is attribution information of the first target IP address; Step c: If the target IP address information exists, return the target IP address information; Step d: If the information of the first target IP address does not exist, execute the above steps 1 to 3 until the information of the target IP address is returned or the multiple subnet masks are all queried.
10. The device according to claim 9, characterized in that The target regular expression includes: a first target regular expression or a second target regular expression; The network number in the first target regular expression is: the value of the first preset field is adjusted to the difference between the first preset field and the first remainder; the first remainder is the remainder obtained by dividing the value of the first preset field by the number of hosts; The network number in the second target regular expression is: the value of the second preset field is adjusted to the difference between the second preset field and the second remainder; and the first preset field is replaced with a fixed value; the second remainder is the remainder obtained by dividing the value of the second preset field by the number of hosts; the fixed value is a natural number.
11. An IP address query device, characterized in that: include: A processor and a communication interface; the communication interface is coupled to the processor, and the processor is used to run a computer program or instruction to implement the IP address query method as described in any one of claims 1-5.
12. A computer-readable storage medium storing instructions, characterized in that: When a computer executes the instruction, the computer executes the IP address query method described in any one of claims 1 to 5.
Citation Information
Patent Citations
IP address ownership information indexing and fast querying method
CN103561133A
IP attribution determination method and device and computer storage medium
CN109783521A