Method and device for retrieving IP address
By converting the IP address database to binary format and dividing it into sub-retrieval segments, a fast retrieval table is constructed. The binary search method is used to quickly locate IP addresses, solving the problems of cache misses and memory access latency in large-scale IP address database queries, and achieving efficient querying and good scalability.
Patent Information
- Application Number
- CN202510883563.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-29
- Publication Date
- 2025-10-21
AI Technical Summary
Existing technologies suffer from high cache miss rates, memory access latency, and poor scalability when querying large-scale IP address databases, especially with performance degradation in high-concurrency scenarios.
By converting the IP address database into binary format and dividing it into multiple sub-segments, a fast search table is constructed. A binary search method is used to quickly locate the sub-segments at the first level, and the region ID of the target IP address is accurately queried at the second level, reducing memory access and cache misses.
It significantly improves query efficiency, reduces cache miss rate and resource consumption, and is suitable for large-scale distributed systems and resource-constrained environments.
Smart Images

Figure CN120825481A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer information processing, and in particular to a method and device for retrieving an IP address. Background Art
[0002] With the widespread adoption and growth of the internet, IP addresses (Internet Protocol Addresses) have become the foundation for network device identification and communication. An IP address database is a data structure that maps IP address segments to geographic regions or other attribute information. It is widely used in areas such as location-based services (LBS), content delivery networks (CDNs), network routing optimization, and network security analysis.
[0003] Currently, two IP address protocols, IPv4 and IPv6, coexist globally. IPv4 addresses are 32 bits long, with a relatively limited number of addresses, and are commonly used in traditional networks. IPv6 addresses, on the other hand, are 128 bits long, providing a vast address space and representing the mainstream trend in future network development. Both IPv4 and IPv6 address databases are experiencing rapid growth in global applications. In particular, in applications involving queries involving geographic regions or other attributes, IP address databases can contain millions or even tens of millions of address segment records.
[0004] Technically, IP address databases are typically stored as address segments, with each record containing a starting address, an ending address, and related attributes (such as region and service type). In practice, querying the address segment to which an IP address belongs is a common operation, and its performance directly impacts system response speed. Whether using IPv4 or IPv6 IP address databases, current technology faces performance bottlenecks in large-scale data queries. A new technical solution is urgently needed to improve query efficiency, reduce memory access latency, and provide good scalability to cope with future data growth.
[0005] Therefore, a new method and device for retrieving an IP address is needed.
[0006] The above information disclosed in this Background section is only for enhancement of understanding of the background of the application and therefore it may contain information that does not form the prior art that is already known to a person of ordinary skill in the art. Summary of the Invention
[0007] In view of this, the present application provides an IP address retrieval method and device, which can effectively improve query efficiency and reduce cache miss rate, reduce CPU and memory resource usage, and have lower requirements on device performance. It is suitable for large-scale distributed systems and resource-constrained environments.
[0008] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by practice of the present application.
[0009] According to one aspect of the present application, a method for retrieving an IP address is proposed, which includes: obtaining a target IP address to be retrieved; converting the target IP address into a corresponding binary format; searching a quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; searching the sub-retrieval segment to determine the region ID corresponding to the target IP address; converting the region ID into a region name and returning the result.
[0010] In an exemplary embodiment of the present application, it also includes: generating a binary IP retrieval library through IP address segments in text format; dividing the binary IP retrieval library into multiple sub-retrieval segments based on the total number of IP address segments; and constructing the quick retrieval table based on the attribute information of each sub-retrieval segment.
[0011] In an exemplary embodiment of the present application, a binary IP retrieval library is generated using IP address segments in text format, including: converting the IP address segments in text format into binary format; and sorting the IP address segments in ascending order according to their corresponding starting addresses to generate a binary IP retrieval library.
[0012] In an exemplary embodiment of the present application, an IP address segment in text format is converted into a binary format, including: obtaining the starting address and ending address of each address segment in the IP address library in text format; converting the starting address and the ending address into binary representation; and converting the region name corresponding to the IP address into a region ID.
[0013] In an exemplary embodiment of the present application, the binary IP retrieval library is divided into multiple sub-retrieval segments based on the total number of IP address segments, including: calculating the total number N of IP address segments by square root method to obtain the number of segments M; and evenly dividing the address segment set into M sub-retrieval segments.
[0014] In an exemplary embodiment of the present application, the quick retrieval table is constructed based on the attribute information of each sub-retrieval segment, including: extracting the starting address of the first address segment, the ending address of the tail address segment and the sub-segment index of each sub-retrieval segment to construct the quick retrieval table.
[0015] In an exemplary embodiment of the present application, searching the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs includes: searching the quick retrieval table by binary search to determine the sub-retrieval segment to which the target IP address belongs.
[0016] In an exemplary embodiment of the present application, searching the sub-search segment to determine the region ID corresponding to the target IP address includes: searching the sub-search segment by binary search to determine the region ID corresponding to the target IP address.
[0017] According to one aspect of the present application, a device for retrieving an IP address is proposed, which includes: an acquisition module for acquiring a target IP address to be retrieved; a conversion module for converting the target IP address into a corresponding binary format; a retrieval segment module for searching a quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; a region module for searching the sub-retrieval segment to determine the region ID corresponding to the target IP address; and a result module for converting the region ID into a region name and returning the result.
[0018] In an exemplary embodiment of the present application, it also includes: a retrieval table module, which is used to generate a binary IP retrieval library through IP address segments in text format; divide the binary IP retrieval library into multiple sub-retrieval segments based on the total number of IP address segments; and construct the quick retrieval table based on the attribute information of each sub-retrieval segment.
[0019] According to one aspect of the present application, an electronic device is proposed, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.
[0020] According to one aspect of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.
[0021] According to the IP address retrieval method and device of the present application, by obtaining the target IP address to be retrieved; converting the target IP address into a corresponding binary format; searching the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; searching the sub-retrieval segment to determine the region ID corresponding to the target IP address; converting the region ID into a region name and returning the result, the method can effectively improve query efficiency and reduce cache miss rate, reduce CPU and memory resource usage, and have lower requirements on device performance. It is suitable for large-scale distributed systems and resource-constrained environments.
[0022] It should be understood that the foregoing general description and the following detailed description are merely illustrative and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The above and other objects, features, and advantages of the present application will become more apparent by describing in detail exemplary embodiments thereof with reference to the accompanying drawings. The drawings described below are merely some embodiments of the present application, and it is apparent to those skilled in the art that other drawings can be derived from these drawings without inventive effort.
[0024] Figure 1 The figure is a flowchart showing a method for retrieving an IP address according to an exemplary embodiment.
[0025] Figure 2 The figure is a flowchart showing a method for retrieving an IP address according to another exemplary embodiment.
[0026] Figure 3 The figure is a flowchart showing a method for retrieving an IP address according to another exemplary embodiment.
[0027] Figure 4 The figure is a block diagram of a device for retrieving an IP address according to an exemplary embodiment.
[0028] Figure 5 It is a block diagram of an electronic device according to an exemplary embodiment.
[0029] Figure 6 It is a block diagram of a computer-readable medium according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be embodied in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art. Like reference numerals in the drawings represent like or similar parts, and thus repetitive description thereof will be omitted.
[0031] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner.In the following description, many specific details are provided so as to provide a full understanding of the embodiments of the present application. However, it will be appreciated by those skilled in the art that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps etc. can be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0033] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.
[0034] It should be understood that although the terms first, second, third, etc. may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another. Thus, the first component discussed below could be referred to as the second component without departing from the teachings of the present invention. As used herein, the term "and / or" includes any one and all combinations of one or more of the associated listed items.
[0035] Those skilled in the art will understand that the drawings are merely schematic diagrams of example embodiments, and the modules or processes in the drawings are not necessarily necessary for implementing the present application, and therefore cannot be used to limit the scope of protection of the present application.
[0036] The technical abbreviations involved in this application are explained as follows:
[0037] ID (Identifier): A unique code used to represent a region, service type, or other attribute information, facilitating the storage and quick query of structured data.
[0038] CPU (Central Processing Unit): The core processing unit of a computer system, responsible for executing instructions and processing data. During the IP address query process, it performs tasks such as computing logic and data access control.
[0039] Cache: A high-speed cache storage area located between the CPU and main memory, used to store recently or frequently used data to increase data access speed and reduce memory access latency.
[0040] Cache Miss: This occurs when the data requested by the CPU does not hit the cache and needs to be reloaded from the main memory (RAM), usually resulting in processing delays.
[0041] RAM (Random Access Memory): The main memory in a computer, responsible for storing the operating system, applications, and currently processed data, and is the main carrier of data during operation.
[0042] After a long period of research, the applicant in this case found that in the prior art, the construction and retrieval of IP address databases generally include the following process:
[0043] Build process:
[0044] (1) Address binarization: Convert the "start address" and "end address" in each address segment in the IP address database into binary form, and convert the "region" information into an integer type region ID to form structured data: "binary start address | binary end address | region ID".
[0045] (2) Address sorting: Sort all address segments in ascending order according to the starting address to form a complete IPv6 address retrieval library.
[0046] Search process:
[0047] Use the binary search method to query the sorted binary address database. The specific process is as follows: the target IP address is converted into binary. In each comparison, the range is determined by comparing it with the binary start and end addresses stored in the address database. Based on the principle of binary search, the search range is gradually narrowed until the address segment containing the target address is found and the corresponding region ID is returned.
[0048] The advantage of this solution is that it can efficiently process large-scale data queries in theory by leveraging the logarithmic time complexity O(logN) of the bisection method.
[0049] Although the existing technical solution uses the binary search method to reduce the time complexity of the query, it has the following significant shortcomings in practical applications:
[0050] Cache misses: During queries, the CPU frequently accesses large amounts of binary data. When the data cannot be fully stored in the CPU cache, queries frequently trigger cache misses, forcing the CPU to load data from memory multiple times, significantly increasing query latency.
[0051] Query performance bottleneck: Since queries require loading data from memory multiple times, even using binary search, the memory access time for a single query is still long. In high-concurrency query scenarios, the performance degradation problem is particularly obvious.
[0052] Poor scalability: As the size of the IP address database continues to expand, the query efficiency of the existing solution may further decrease, making it difficult to meet the needs of large-scale real-time queries.
[0053] In summary, existing technical solutions cannot fully solve the problems of cache misses and memory access delays in large-scale IP address database queries, and an improved solution is urgently needed to improve query efficiency.
[0054] This application proposes an improved solution to address the performance bottlenecks in existing technologies when processing large-scale IP address database queries, especially the query delay problem caused by CPU cache misses. The problems to be solved by this application are as follows:
[0055] 1. Reduce the number of memory accesses during the query process: By optimizing the data structure and query process, the frequency of direct access to large-scale address libraries is reduced, reducing the possibility of cache misses.
[0056] 2. Improve query efficiency: Narrow the query scope and speed up the location of the target address to meet real-time query needs in high-concurrency scenarios.
[0057] 3. Enhance system scalability: This allows the solution to maintain good query performance even when the address database is further expanded.
[0058] The content of this application is described in detail below with the help of specific embodiments.
[0059] Figure 1 FIG1 is a flowchart of a method for retrieving an IP address according to an exemplary embodiment. The method 10 for retrieving an IP address includes at least steps S102 to S110.
[0060] like Figure 1 As shown, in S102, the target IP address to be searched is obtained. After receiving the query request, the system extracts the target IP address to be searched from the input.
[0061] For example, the target IP address is "2400:cb00:2048:1::c629:d7a2" (IPv6 address).
[0062] In S104, the target IP address is converted into a corresponding binary format.
[0063] The above IPv6 address is standardized and converted into a 128-bit binary representation for subsequent comparison with the binary start and end addresses of the address segment.
[0064] For example, the conversion result is a binary number with a length of 128 bits:
[0065] 1010010000000000.......
[0066] In S106, the quick search table is searched to determine the sub-search segment to which the target IP address belongs. The quick search table can be searched by a binary search method to determine the sub-search segment to which the target IP address belongs.
[0067] Perform a binary search on a pre-built quick search table. The quick search table records the start and end addresses and indexes of each sub-search segment. During the search, the system determines whether the target IP address falls within the address range of a table entry.
[0068] For example, a record in the quick search table is:
[0069] Starting address: 2400:cb00::
[0070] Binary starting: 1010010000000000......
[0071] End address: 2400:cb00:ffff:ffff:ffff:ffff:ffff:ffff
[0072] Index: Subsection 12
[0073] If the binary value of the target IP address falls within the range, it is determined to belong to the 12th sub-search segment.
[0074] In S108, the sub-search segment is searched to determine the region ID corresponding to the target IP address. The sub-search segment can be searched by a binary search method to determine the region ID corresponding to the target IP address.
[0075] Enter the 12th sub-search segment and perform a binary search on the address segments in this sub-segment. Each address segment contains a starting address, an ending address, and a corresponding region ID.
[0076] For example, subsegment 12 contains the following address segments:
[0077] Address segment 1: Start: 2400:cb00:2048:1::c600:0000
[0078] End: 2400:cb00:2048:1::c6ff:ffff
[0079] Region ID: 105
[0080] Address segment 2: Start: 2400:cb00:2048:1::c700:0000
[0081] End: 2400:cb00:2048:1::c7ff:ffff
[0082] Region ID: 106
[0083] If the target IP address is within the range of address segment 1, the region ID is returned as 105.
[0084] In S110, the region ID is converted into a region name and the result is returned. According to the region ID (such as 105), a pre-built region mapping table is searched and the corresponding region name is returned.
[0085] For example, region ID 105 corresponds to "XX City", and the system returns the result as "XX City".
[0086] First-level search: Use binary search in the quick search table to quickly determine the sub-search segment to which the target IP belongs.
[0087] Second-level search: Use binary search in the target sub-search segment to further locate the region to which the target IP address belongs.
[0088] In this solution, the first level of retrieval in the retrieval process (quick retrieval table query) can be completely stored in the CPU cache because the quick retrieval table occupies a small amount of storage space. The CPU only needs to load the cache once to calculate the index of the sub-retrieval segment. The second level of retrieval in the retrieval process (precise query within the sub-segment) has a greatly reduced number of address segments in each field, which is at the square root level of the total number. Therefore, the space occupied by the address segments can also be completely stored in the CPU cache. The CPU only needs to load the cache once to calculate the regional ID corresponding to the IP address. Ultimately, this solution can retrieve the result with at most two cache loads.
[0089] According to the IP address retrieval method of the present application, by obtaining the target IP address to be retrieved; converting the target IP address into a corresponding binary format; searching the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; searching the sub-retrieval segment to determine the region ID corresponding to the target IP address; converting the region ID into a region name and returning the result, the method can effectively improve query efficiency and reduce cache miss rate, reduce CPU and memory resource usage, and have lower requirements on device performance. It is suitable for large-scale distributed systems and resource-constrained environments.
[0090] It should be clearly understood that this application describes how to form and use specific examples, but the principles of this application are not limited to any details of these examples. On the contrary, based on the teaching of the content disclosed in this application, these principles can be applied to many other embodiments.
[0091] Figure 2 FIG2 is a flow chart showing a method for retrieving an IP address according to another exemplary embodiment. The method 20 for retrieving an IP address includes at least steps S202 to S208.
[0092] like Figure 2 As shown, in S202, a binary IP search library is generated using the text-formatted IP address segments. For example, the text-formatted IP address segments can be converted into binary format; and the IP address segments are sorted in ascending order according to their corresponding starting addresses to generate the binary IP search library.
[0093] More specifically, the starting address and ending address of each address segment in the text-formatted IP address library can be obtained; the starting address and the ending address can be converted into binary representations; and the region name corresponding to the IP address can be converted into a region ID.
[0094] In a specific embodiment, the original text format IP address segment library (for example, "192.168.0.0-192.168.255.255, region A") is converted into a structured binary format data set, specifically including:
[0095] Get the starting address and ending address of each address segment;
[0096] Convert the start and end addresses into fixed-length binary representations (e.g., 32 bits for IPv4 and 128 bits for IPv6).
[0097] Map the region name corresponding to each address segment to a unique region ID to reduce storage and matching costs;
[0098] Sort all address segments in ascending order according to their binary starting addresses to form a basic binary IP retrieval library.
[0099] Example:
[0100] Original text record:
[0101] "2400:cb00::-2400:cb00:ffff:ffff:ffff:ffff:ffff:ffff, Beijing"
[0102] After conversion:
[0103] Starting address (binary): 001001001100....0000 (128 bits)
[0104] End address (binary): 001001001100....1111
[0105] Region ID: 105
[0106] Once formed, the retrieval library will serve as the input basis for subsequent segmentation and quick retrieval table generation.
[0107] In S204, the binary IP search library is divided into a plurality of sub-search segments based on the total number of IP address segments. For example, the total number N of IP address segments can be calculated by square root to obtain the number of segments M; and the address segment set is evenly divided into M sub-search segments.
[0108] The IP address database is segmented by rounding the square root of the number of address segments, so that each sub-segment contains a relatively balanced number of address segments. The number and range of segments are dynamically adapted to the database size, balancing the size of the fast retrieval table and the query efficiency within the sub-segment.
[0109] To improve the efficiency of subsequent queries, the above binary IP search library is divided according to the number of address segments. The steps are as follows:
[0110] Assume that the total number of original address segments is N, and the number of segments M is calculated as M = √N;
[0111] Divide the address segment set into M sub-search segments evenly, so that each sub-segment contains approximately N / M address segments;
[0112] Use sequential segmentation: the i-th sub-segment contains the (i-1)*N / M-th to i*N / M-1-th address segments.
[0113] Use the square root rule to segment and strike a balance between cache space and sub-segment search efficiency;
[0114] The number of address segments within each sub-segment is basically balanced, which is conducive to fast positioning and cache loading.
[0115] In S206, the quick search table is constructed based on the attribute information of each sub-search segment. The quick search table is constructed by extracting the starting address of the first address segment, the ending address of the last address segment, and the sub-segment index for each sub-search segment. The segmented data is stored in a continuous memory area, ensuring greater locality within the sub-segment and further improving cache utilization efficiency.
[0116] Figure 3 The figure is a flowchart showing a method for retrieving an IP address according to another exemplary embodiment. Figure 3 The process 30 shown is Figure 2 A detailed description of the process shown.
[0117] like Figure 3 As shown, in S302, the IP address segment in text format is converted into a binary IP search library.
[0118] Convert each address segment in the text-format IP address library into a structured binary format.
[0119] The original format of the IP address database is: "start address|end address|region".
[0120] First, create a region table for the region and convert the region name into a region ID. Then, convert the start and end addresses in text format into binary format. The final converted format is:
[0121] "Binary start address | Binary end address | Region ID".
[0122] Finally, all text segments are converted into a complete IP retrieval address library.
[0123] In S304, the binary IP search library is sorted in ascending order.
[0124] All address segments are sorted in ascending order according to the binary value of the starting address to form an ordered retrieval address library for efficient execution of subsequent retrieval algorithms.
[0125] In S306, the number of sub-search segments is calculated.
[0126] The sub-index segments are divided according to the square root of the total number of address segments. Assuming the total number of address segments is N, the number of sub-index segments M is: M = rounded (square root (N)).
[0127] The sorted IP address database is evenly divided into M sub-search segments, each of which contains approximately N / M address segments.
[0128] In S308, the number of IP addresses in each sub-search segment is calculated.
[0129] In S310, a quick search table is constructed according to the start and end IP addresses of the sub-search segment.
[0130] The following information is extracted from each sub-segment to construct a quick search table: the starting address of the first address segment; the ending address of the last address segment; and the sub-segment index (which identifies the sub-segment's location in the address database). The quick search segment format is: "Start address of first address segment | End address of last address segment | Sub-segment index." The quick search table is sorted by sub-segment starting address, allowing you to quickly locate the sub-segment to which the target IP address belongs.
[0131] In S312, the quick search table and the binary IP search library form a complete search library.
[0132] This application can effectively improve query efficiency and reduce cache miss rates by segmenting the IP address database and introducing it into a fast retrieval table. This is specifically reflected in the following aspects:
[0133] (1) Query efficiency is significantly improved:
[0134] By introducing a quick search table, the sub-search segment to which the target IP belongs can be determined through a small number of range judgments, narrowing the global range query to a local range and reducing the number of binary comparisons.
[0135] (2) Reduce cache miss rate:
[0136] After segment optimization, query operations are mainly concentrated on the data area within the local sub-retrieval segment, reducing the number of main memory accesses, improving the cache hit rate, and thus reducing query latency.
[0137] (3) Good scalability:
[0138] The present invention is applicable to ultra-large-scale IP address libraries, and the segmentation mechanism and the fast retrieval table can be dynamically adjusted according to the library scale, supporting more efficient address segment management and query.
[0139] (4) Reduced resource consumption:
[0140] Segmented query reduces the scope of global retrieval, reduces CPU and memory resource usage, and places lower requirements on device performance. It is suitable for large-scale distributed systems and resource-constrained environments.
[0141] Those skilled in the art will appreciate that all or part of the steps implementing the above embodiments can be implemented as a computer program executed by a CPU. When executed by the CPU, the computer program performs the functions defined in the above method provided herein. The program can be stored in a computer-readable storage medium, such as a read-only memory, a magnetic disk, or an optical disk.
[0142] Furthermore, it should be noted that the aforementioned figures are merely illustrative of the processes included in the methods according to exemplary embodiments of the present application and are not intended to be limiting. It is readily understood that the processes illustrated in the aforementioned figures do not indicate or limit the temporal order of these processes. Furthermore, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0143] The following are device embodiments of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0144] Figure 4 FIG. 1 is a block diagram of an IP address retrieval device according to an exemplary embodiment. Figure 4 As shown, the IP address search device 40 includes: an acquisition module 402, a conversion module 404, a search segment module 406, a region module 408, and a result module 410. The IP address search device 40 may also include: a search table module 412.
[0145] The acquisition module 402 is used to obtain the target IP address to be retrieved;
[0146] The conversion module 404 is used to convert the target IP address into a corresponding binary format;
[0147] The retrieval segment module 406 is used to search the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs;
[0148] The region module 408 is used to search the sub-search segment to determine the region ID corresponding to the target IP address;
[0149] The result module 410 is used to convert the region ID into a region name and return the result.
[0150] The search table module 412 is used to generate a binary IP search library using text-formatted IP address segments; divide the binary IP search library into multiple sub-search segments based on the total number of IP address segments; and construct the quick search table based on the attribute information of each sub-search segment.
[0151] According to the IP address retrieval device of the present application, by obtaining the target IP address to be retrieved; converting the target IP address into a corresponding binary format; searching the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; searching the sub-retrieval segment to determine the region ID corresponding to the target IP address; converting the region ID into a region name and returning the result, the method can effectively improve the query efficiency and reduce the cache miss rate, reduce the resource usage of the CPU and memory, and have lower requirements on device performance. It is suitable for large-scale distributed systems and resource-constrained environments.
[0152] Figure 5 It is a block diagram of an electronic device according to an exemplary embodiment.
[0153] Refer to the following Figure 5 hereinafter, an electronic device 500 according to this embodiment of the present application is described. Figure 5 The electronic device 500 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0154] like Figure 5 As shown, electronic device 500 is implemented as a general-purpose computing device. Components of electronic device 500 may include, but are not limited to, at least one processing unit 510, at least one storage unit 520, a bus 530 connecting various system components (including storage unit 520 and processing unit 510), a display unit 540, and the like.
[0155] The storage unit stores program codes, which can be executed by the processing unit 510, so that the processing unit 510 performs the steps described in this specification according to various exemplary embodiments of the present application. For example, the processing unit 510 can perform the following steps: Figure 1 , Figure 2 , Figure 3 Follow the steps shown in .
[0156] The storage unit 520 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 5201 and / or a cache memory unit 5202 , and may further include a read-only memory unit (ROM) 5203 .
[0157] The storage unit 520 may also include a program / utility 5204 having a set (at least one) of program modules 5205, such program modules 5205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.
[0158] Bus 530 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0159] The electronic device 500 can also communicate with one or more external devices 500' (e.g., a keyboard, pointing device, Bluetooth device, etc.), devices that allow a user to interact with the electronic device 500, and / or any device that allows the electronic device 500 to communicate with one or more other computing devices (e.g., a router, modem, etc.). This communication can occur via an input / output (I / O) interface 550. Furthermore, the electronic device 500 can communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 560. The network adapter 560 can communicate with other modules of the electronic device 500 via the bus 530. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with the electronic device 500, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0160] Through the above description of the embodiments, it is easy for those skilled in the art to understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Figure 6As shown, the technical solution according to the embodiment of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the above method according to the embodiment of the present application.
[0161] The software product can be any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0162] The computer-readable storage medium may include a data signal propagated in baseband or as part of a carrier wave, wherein the readable program code is carried. The data signal propagated may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or component. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.
[0163] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0164] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by a device, the computer-readable medium implements the following functions: obtaining the target IP address to be retrieved; converting the target IP address into a corresponding binary format; searching the quick search table to determine the sub-search segment to which the target IP address belongs; searching the sub-search segment to determine the region ID corresponding to the target IP address; converting the region ID into a region name and returning the result.
[0165] Those skilled in the art will appreciate that the modules described above can be distributed in the device according to the description of the embodiment, or can be modified accordingly to be used in one or more devices that are different from the embodiment. The modules of the above embodiment can be combined into one module or further divided into multiple submodules.
[0166] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
[0167] While the exemplary embodiments of the present application have been specifically illustrated and described above, it should be understood that the present application is not limited to the detailed structures, configurations, or implementations described herein; rather, the present application is intended to encompass various modifications and equivalent configurations within the spirit and scope of the appended claims.
Claims
1. A method for retrieving an IP address, characterized in that: include: Get the target IP address to be retrieved; Convert the target IP address into a corresponding binary format; Searching the quick search table to determine the sub-search segment to which the target IP address belongs; Searching the sub-search segment to determine the region ID corresponding to the target IP address; Converts the region ID to a region name and returns the result.
2. The method according to claim 1, wherein Also includes: Generate a binary IP search library using text-formatted IP address segments; Dividing the binary IP search library into a plurality of sub-search segments based on the total number of IP address segments; The quick search table is constructed based on the attribute information of each sub-search segment.
3. The method according to claim 2, wherein Generate a binary IP search library from text-formatted IP address segments, including: Convert the IP address segment in text format to binary format; Sort the IP address segments in ascending order according to their corresponding starting addresses to generate a binary IP search library.
4. The method according to claim 3, wherein Converts text-formatted IP address segments to binary format, including: Get the starting address and ending address of each address segment in the text-formatted IP address database; Convert the start address and end address into binary representation; Convert the region name corresponding to the IP address to a region ID.
5. The method according to claim 2, wherein The binary IP search library is divided into multiple sub-search segments based on the total number of IP address segments, including: Calculate the total number of IP address segments N using the square root method to get the number of segments M. The address segment set is evenly divided into M sub-search segments.
6. The method according to claim 2, wherein Constructing the quick search table based on the attribute information of each sub-search segment includes: The starting address of the first address segment, the ending address of the last address segment and the sub-segment index are extracted for each sub-search segment to construct the quick search table.
7. The method according to claim 1, wherein Searching the quick search table to determine the sub-search segment to which the target IP address belongs includes: The quick search table is searched by binary search to determine the sub-search segment to which the target IP address belongs.
8. The method according to claim 1, wherein Searching the sub-search segment to determine the region ID corresponding to the target IP address includes: The sub-search segment is searched by binary search to determine the region ID corresponding to the target IP address.
9. An IP address retrieval device, characterized in that: include: An acquisition module is used to obtain the target IP address to be retrieved; A conversion module, configured to convert the target IP address into a corresponding binary format; A retrieval segment module, configured to search the quick retrieval table to determine the sub-retrieval segment to which the target IP address belongs; A region module, configured to search the sub-search segment to determine the region ID corresponding to the target IP address; The result module is used to convert the region ID into a region name and return the result.
10. The device according to claim 9, wherein Also includes: The retrieval table module is used to generate a binary IP retrieval library through IP address segments in text format; divide the binary IP retrieval library into multiple sub-retrieval segments based on the total number of IP address segments; and construct the quick retrieval table based on the attribute information of each sub-retrieval segment.