IP attribution query method, IP information array construction method and electronic equipment

By building multi-level arrays and storing offsets in array elements, the problems of low efficiency of IP home query, large memory consumption, precision and timeliness in the prior art are solved, and efficient, accurate and reliable IP home query is achieved.

CN120067234AInactive Publication Date: 2025-05-30HUNDSUN TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510542057.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2025-05-30
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the prior art, IP home query efficiency is low, memory consumption is high, and accuracy, timeliness and reliability are insufficient.

Method used

By hierarchically storing the IP address and its home information, a multi-level array is built, and offsets pointing to the next level of array elements are stored in the array elements to improve the performance of data queries and reduce memory usage.

Benefits of technology

It effectively improves the efficiency and accuracy of IP home information query, reduces memory consumption, and improves the reliability and timeliness of query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120067234A_ABST
    Figure CN120067234A_ABST
Patent Text Reader

Abstract

The invention provides an IP attribution query method, an IP information array construction method and electronic equipment, and the method comprises the steps: obtaining a first IP sub-address and a second IP sub-address of a to-be-queried IP address, searching a first array element containing the first IP sub-address in a first array, and obtaining a first offset in the first array element, and taking the first offset as an initial search position of a second array, searching a second array element containing a second IP sub-address in the second array, obtaining a second offset in the second array element, and querying according to the second offset and the at least one IP attribution information array to obtain an attribution query result of the to-be-queried IP address, by storing the attribution information related to the IP address in the array, the memory occupation of the IP data can be reduced. And when the IP attribution is queried, the query efficiency of IP attribution information query can be greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method for querying IP attribution, a method for constructing an IP information array, and an electronic device. Background Art

[0002] IP (Internet Protocol Address) attribution query is a technology that determines the corresponding geographical location (such as country, region, city, etc.) by analyzing the IP address. IP attribution query has a wide range of applications in multiple scenarios such as security monitoring, risk management, compliance inspection, and optimizing user experience.

[0003] In the prior art, the methods for IP attribution query include: IP attribution query technology based on a database, query technology for IP address location based on an API (Application Programming Interface), and IP attribution location technology based on a hash algorithm, etc.

[0004] However, the IP attribution query technology based on a database has problems such as slow query speed and large memory consumption, and it is also difficult to ensure the accuracy and integrity of the data. The query technology for IP address location based on an API depends on external services and has problems such as insufficient reliability and poor timeliness. The IP attribution location technology based on a hash algorithm may have problems of hash conflicts, which will also affect the query performance. Summary of the Invention

[0005] The purpose of this application is to provide a method for querying IP attribution, a method for constructing an IP information array, and an electronic device to solve the problems of low efficiency, large memory consumption, and insufficient accuracy, timeliness, and reliability in IP attribution query in the prior art.

[0006] To achieve the above purpose, the technical solution adopted in this application is as follows: In the first aspect, this application provides a method for querying IP attribution, and the method includes: Obtain a first IP sub-address and a second IP sub-address of the IP address to be queried, where the first IP sub-address is the first M bytes in the IP address to be queried, and the second IP sub-address is the last N bytes in the IP address to be queried, and both M and N are integers greater than 0; Find a first array element containing the first IP sub-address in a first array, and obtain a first offset in the first array element; Using the first offset as the starting search position of the second array, search for the second array element containing the second IP sub-address in the second array, and obtain the second offset in the second array element, where the second offset is used to indicate the starting storage position of the location information of the IP address to be queried in the IP location information array; According to the second offset and at least one IP location information array, query and obtain the location query result of the IP address to be queried.

[0007] In a second aspect, an embodiment of the present application further provides a method for constructing an IP information array, including: Obtain a first file and a second file, where the first file and the second file are associated through an association identifier. The first file includes: an association identifier and multiple address range sets, and each address range set includes multiple IP addresses with the same IP information. The IP information includes: postal code, longitude and latitude. The second file includes: first location information, second location information, and the association identifier; Construct a first array, a second array, and at least one IP location information array according to the first file and the second file.

[0008] In a third aspect, an embodiment of the present application further provides an electronic device, including: a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to perform the steps of an IP location query method as described in the first aspect or an IP information array construction method as described in the second aspect.

[0009] The beneficial effects of the present application are: The IP address and the location information of the IP address are hierarchically stored in multiple arrays. The subscript of the array can represent the position of the data, so the space for recording the data position is saved. And it is saved in the form of an array rather than an object, which also reduces the memory cost and time cost brought by creating, maintaining, and destroying objects. By constructing multiple levels of arrays and storing the offset pointing to the next-level array element in the array element, the performance of data query can be effectively improved, and the memory usage can be reduced. When performing an IP location query, the query range can be gradually narrowed based on multiple levels of arrays, without having to compare with all IP addresses in the database. Compared with the hash calculation and database query methods, it not only reduces the query time, improves the query efficiency, but also improves the query accuracy.

[0010] To make the above objects, features, and advantages of the present application more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes a detailed description as follows. Brief Description of the Drawings

[0011] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for the embodiments will be briefly introduced below. It should be understood that the following accompanying drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related accompanying drawings can also be obtained based on these drawings.

[0012] Figure 1 Shows a flowchart of a method for querying IP ownership location provided by an embodiment of the present application; Figure 2 Shows a schematic flowchart of a process for finding array elements in a first array and a second array provided by an embodiment of the present application; Figure 3 Shows a flowchart of a method for querying an IP ownership information array provided by an embodiment of the present application; Figure 4 Shows a schematic flowchart of a method for querying IP ownership location provided by an embodiment of the present application; Figure 5 Shows a flowchart of a method for constructing an IP information array provided by an embodiment of the present application; Figure 6 Shows a flowchart of a process for constructing a first array, a second array, and an IP ownership information array provided by an embodiment of the present application; Figure 7 Shows a flowchart of a process for constructing an IP ownership information array provided by an embodiment of the present application; Figure 8 Shows a flowchart of a process for constructing a third array provided by an embodiment of the present application; Figure 9 Shows a flowchart of a process for preprocessing a first file provided by an embodiment of the present application; Figure 10 Shows a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed Description of the Embodiments

[0013] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this application. Apparently, the described embodiments are only a part rather than all of the embodiments of this application. Usually, the components of the embodiments of this application described and illustrated in the accompanying drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative efforts shall fall within the scope of protection of this application.

[0014] It should be noted that the term "including" will be used in the embodiments of this application to indicate the existence of the subsequently stated features, but does not exclude the addition of other features.

[0015] Before introducing the technical solutions of the embodiments of this application, it should be noted that for the IP address location query method provided in the embodiments of this application, before collecting and generating personal information and important data during the execution process, explicit consent from the user must be obtained before it can be applied to the solutions of the embodiments of this application. At the same time, the personal information and important data collected and generated during the execution process of the IP address location query method provided in the embodiments of this application must follow the principles of legality, legitimacy, and necessity, disclose the collection and use rules, and clearly state the purpose, method, and scope of collecting and using information. The relevant data in the above examples do not include personal information unrelated to the relevant services provided in the above examples.

[0016] In the prior art, the methods for querying IP address locations include IP address location query technologies based on databases, query technologies for IP address location based on APIs, and IP address location technologies based on hash algorithms, etc.

[0017] Among them, the database query technology relies on a pre-constructed database that contains a large number of IP address ranges and their corresponding geographical location information. When querying the IP address location, it is necessary to traverse and search the database based on the IP address, or use a hash algorithm to assist in the search. However, this method has the problem of large memory consumption when constructing the database, and there will also be a problem of slow query speed if a large number of IP addresses are saved in the database during the query.

[0018] In addition, in the prior art, IP address location queries can also be performed based on the WHOIS query technology. This method obtains the registration information of the IP address, including the registered organization name and contact address, etc., by accessing the databases of major domain name registration management agencies around the world. However, this method needs to be improved in terms of data accuracy, integrity, query efficiency, and geographical location accuracy.

[0019] The query technology for IP address location based on API refers to accessing external services through API to query the location information of the IP address. However, this method depends on external services. Once there is a service or network interruption, it will seriously affect the reliability and timeliness of IP location query, and the query frequency may also be limited.

[0020] The IP location technology based on the hash algorithm is to perform hash mapping on the IP address and use a hash table or a similar data structure to directly locate the corresponding IP address location information. When querying, the IP address is calculated, and the calculated hash value is mapped in the hash table to obtain the location information corresponding to the IP address. However, when the data volume is large, there may be a problem that multiple different IP addresses are mapped to the same hash value, which will lead to hash conflicts and greatly affect the query performance.

[0021] In addition, in the prior art, the IP address and the location information associated with the IP address are usually stored in a columnar storage manner. When querying the location information associated with the IP address, it is necessary to read and reorganize the data in chunks from multiple columns, which will also increase the complexity and time of the query. In this multi-dimensional query, when the query involves a large number of non-index columns, the split structure of columnar storage will seriously affect the query performance.

[0022] In summary, when querying the location of the IP address in the prior art, there are problems of large memory consumption and low query efficiency.

[0023] Based on this, the present application proposes an IP location query method. By constructing a multi-level array for the IP address and its location information, the IP address and the location information of the IP address are respectively stored in each level of the array, so as to reduce the memory occupancy of the data related to the IP address. And when performing the IP location query, through the combination of the array and the multi-level index, the query efficiency of the IP location information query can be greatly improved.

[0024] Next, in combination with Figure 1 the IP location query method of the present application will be described. The execution subject of this method can be an electronic device with data processing capabilities, such as Figure 1 shown, this method includes: S101. Obtain the first IP sub-address and the second IP sub-address of the IP address to be queried, where the first IP sub-address is the first M bytes in the IP address to be queried, and the second IP sub-address is the last N bytes in the IP address to be queried, and both M and N are integers greater than 0.

[0025] When performing an IP address query, you can first search the IP address to be queried in the commonly used data. The commonly used data includes frequently accessed IP addresses and the location information of the IP addresses. If the commonly used data contains the IP address to be queried, the location information corresponding to the IP address to be queried can be directly returned. If the commonly used data does not contain the IP address to be queried, the IP address to be queried is queried based on steps S101-S103 of the present application to obtain the location information corresponding to the IP address to be queried.

[0026] In the embodiment of the present application, a data source file involved in the application scenario can be obtained in advance, the data source file includes multiple IP address sets and their location information, the IP address set includes multiple IP address intervals, each interval includes multiple IP addresses, and a multi-level array is constructed based on each IP address and the location information of each IP address in the data source file. The array elements in each array are used to store part of the IP address, part of the location information of the IP address, and the position of the array element corresponding to the current array element in the next level array. Therefore, based on the IP address, the location information corresponding to the IP address can be obtained by searching the array level by level.

[0027] The location information corresponding to the IP address includes the latitude and longitude of the IP address, the postal code, the city to which the IP address belongs, the region to which the IP address belongs, and the country, etc.

[0028] The IP address to be queried consists of a first IP sub-address and a second IP sub-address, wherein the first IP sub-address may be the first M bytes of the IP address to be queried, and the second IP sub-address may be the last N bytes of the IP address to be queried, and both M and N are integers greater than 0.

[0029] Exemplarily, the first IP subaddress may be the first two bytes of the IP address to be queried, and the second IP subaddress may be the last two bytes of the IP address to be queried. For example, for the IP address 196.168.100.100, the first IP subaddress may be 196.168, and the second IP subaddress may be 100.100.

[0030] S102: Search for a first array element containing a first IP sub-address in a first array, and obtain a first offset in the first array element.

[0031] Optionally, the first array includes a plurality of array elements, each array element being composed of the first M bytes of the IP address and the first offset corresponding to the IP address. Among them, the first A bytes of each element in the first array are used to store the first M bytes of the IP address, and the remaining bytes of each array element are respectively used to store the first offset corresponding to the IP address. The content of the array elements in the second array includes the remaining bytes of the IP address, and the first offset corresponding to the IP address can indicate the starting storage position of the remaining bytes of the IP address in the second array.

[0032] It should be understood that the first M bytes of multiple IP addresses may be the same. For the convenience of searching, the IP addresses with the same first M bytes can be stored as adjacent array elements in the second array. Assuming that the number of IP addresses with the same first M bytes is a, the first offset is used to indicate the starting storage position of these a IP addresses in the second array. At the same time, the number of IP addresses with the same first M bytes can also be stored in the first array. Therefore, the number of IP addresses with the same first M bytes and the first offset can be found in the first array, so as to determine the starting search position of the IP address in the second array according to the first offset, and determine the search range of the array elements to be searched based on the number of IP addresses with the same first M bytes, so as to find the array element corresponding to the IP address within the search range of the second array.

[0033] S103. Using the first offset as the starting search position of the second array, search for the second array element containing the second IP sub-address in the second array, and obtain the second offset in the second array element, where the second offset is used to indicate the starting storage position of the location information of the IP address to be queried in the IP location information array.

[0034] Optionally, the second array includes a plurality of array elements, each array element being composed of the last N bytes of the IP address and the second offset corresponding to the IP address. Among them, the first B bytes of each element in the second array are used to store the last N bytes of the IP address, and the remaining bytes of each array element are respectively used to store the second offset corresponding to the IP address.

[0035] It should be noted that the first offset indicates the starting search position of the second array element that may contain the second IP sub-address.

[0036] In the first query method, starting from the position indicated by the first offset, the last N bytes of the IP address to be queried can be sequentially matched with each array element to obtain the second array element corresponding to the IP address to be queried in the second array.

[0037] In the second query method, when the array elements in the first array also indicate the number of repeated IP addresses in the first M bytes, the range of array elements corresponding to the IP address to be queried in the second array can be determined based on the first offset and the number of repeated IP addresses, and the array element corresponding to the IP address to be queried in the second array can be obtained by binary search within this range.

[0038] Exemplarily, referring to Figure 2 , assume that the IP address to be queried is 196.168.100.100, the first IP sub-address is the first two bytes 196.168 of the IP address to be queried, and the second IP sub-address is the last two bytes 100.100. There are 1200 IP addresses with 196.168 as the first IP sub-address, and the second IP sub-addresses of these 1200 IP addresses are stored in the second array in ascending order.

[0039] When performing an IP address query, first search for 196.128 in the first array, and the search method can be binary search traversal. If the first 2 bytes of the array element are 192.168, the remaining bytes of the array element can be read to obtain the first offset 25000 corresponding to the IP address to be queried and the repetition count 1200 of 192.168. Next, starting from the first offset 25000 as the starting search position, search for 1200 consecutive array elements starting from the array element indicated by the 25000th byte in the second array, and compare the first B bytes of the second IP sub-address stored in each array element with the second IP sub-address one by one. If the first B bytes of the current array element are 100.100, the remaining bytes of the current array element can be read to obtain the second offset stored in the remaining bytes of the second array element.

[0040] Among them, the second offset is used to indicate the starting storage position of the location information of the IP address to be queried in the IP location information array. It should be noted that the number of IP location information arrays can be multiple, and partial information of the IP address is stored hierarchically in each IP location information array, and the array elements in each IP location information array can indicate the storage position of the array element corresponding to the current array element in the next-level IP location information array.

[0041] Exemplarily, the IP information in the IP location information, that is, longitude and latitude, postal code, can be stored in the next-level array of the second array, and the city information, region, and country information in the IP location information can be stored in the next-level array of the IP information.

[0042] Among them, the second offset of the array elements in the second array can indicate the position of the current array element corresponding to the array element in the array storing IP information. The array elements in the array storing IP information include offsets, and the offsets are used to indicate the positions of the array elements corresponding to the array elements in the arrays storing city information, region information, and country information.

[0043] S104. Query the location query result of the IP address to be queried according to the second offset and at least one IP attribution information array.

[0044] Optionally, the location query result of the IP address includes: longitude and latitude, postal code, city information, region information, and country information.

[0045] As a possible implementation, when the user queries an IP address, the user can also customize the location query result to be returned, and select at least one of longitude and latitude, postal code, city information, region information, and country information as the return result of the location query. This application does not make any restrictions here. Exemplarily, the location query result of the IP address to be queried 192.168.100.100 can be "(30.27, 120.15), 310020, Hangzhou, Zhejiang, China, Asia", where "(30.27, 120.15)" is the longitude and latitude, and "310020" is the postal code.

[0046] When the user customizes the location query result to be returned, after querying all the location information of the IP address, the user can filter and return the customized location query result from the location information.

[0047] In the first implementation, the IP attribution information array includes: a third array storing longitude and latitude and postal code, a fourth array storing city information, and a fifth array storing region information and country information. Each data element in the third array includes longitude and latitude, postal code, and an offset value pointing to the fourth array. Each array element in the fourth array includes city information and an offset value pointing to the fifth array. Each array element in the fifth array includes region information and country information. According to the second offset, the array element corresponding to the IP address to be queried in the third array can be determined, and the longitude and latitude and postal code of the IP address to be queried can be obtained. And through the offset value of the array element, the city information to which the longitude and latitude and postal code belong, that is, the array element corresponding to the IP address to be queried in the fourth array, can be obtained, and the city information of the IP address to be queried can be obtained. Based on the offset value of the array element, the region and country information to which the city information belongs, that is, the array element corresponding to the IP address to be queried in the fifth array, can be determined, and the region information and country information of the IP address to be queried can be obtained.

[0048] In the second implementation manner, the IP attribution information array includes: a third array storing longitude and latitude and postal codes, a fourth array storing city information, a fifth array storing region information, and a sixth array storing country information. The methods for querying longitude and latitude, postal codes, and city information are the same as those in the first implementation manner described above, and are not elaborated herein in this application. Each array element in the fifth array includes region information and an offset value, and the offset value is used to indicate the position of the array element corresponding to the region information in the sixth array. After determining the array element of the IP address to be queried in the fifth array and obtaining the region information, the array element corresponding to the region information in the sixth array can be determined based on the offset value of the array element, and the country information of the IP address to be queried can be obtained.

[0049] In the third implementation manner, the IP attribution location information array includes: a third array storing longitude and latitude, a fourth array storing postal codes, a fifth array storing city information, and a sixth array storing region information and country information. Each array element in the third array includes longitude and latitude information and an offset value indicating the position of the array element corresponding to the longitude and latitude information in the fourth array. Each array element in the fourth array includes a postal code and an offset value indicating the position of the array element corresponding to the city to which the postal code belongs in the fifth array. Each array element in the fifth array includes city information and the offset values of the regions and countries to which each city belongs corresponding to the array elements in the sixth array. Each array element in the sixth array includes region information and country information.

[0050] Among them, the offset value can be the array subscript of the array element corresponding to the current array element in the next-level array, and the array subscript can indicate the position of the array element in the array.

[0051] It should be noted that the above are only three possible implementation manners of the IP attribution information array given in this application. It should be understood that the IP attribution location information can also be divided into arrays at multiple levels in other ways. Except for the arrays at the last level, the array elements in the arrays at the other levels include the partial IP attribution location information stored in the current array, and the position of the array element corresponding to the next part of the IP attribution location information corresponding to this part of the IP attribution location information in the next-level array. Other implementation manners are not elaborated herein in this application.

[0052] In the embodiments of the present application, the IP address and the location information of the IP address are hierarchically stored in multiple arrays. The subscript of the array can represent the position of the data, thus saving the space for recording the data position. Moreover, since it is stored in the form of an array rather than an object, the memory cost and time cost brought by creating, maintaining, and destroying the object are also reduced. By constructing multiple levels of arrays and storing the offsets pointing to the array elements of the next level in the array elements, the performance of data query can be effectively improved, and the memory usage can be reduced. When querying the location of the IP address, the query range can be gradually narrowed based on multiple levels of arrays, without having to compare with all IP addresses in the database. Compared with the methods of hash calculation and database query, not only the query time is reduced and the query efficiency is improved, but also the query accuracy is improved.

[0053] Optionally, the at least one IP location information array includes: a third array, a fourth array, and a fifth array. The following is a further description of the query result of the location of the IP address to be queried obtained according to the second offset and the multiple IP location information arrays, as Figure 3 shown, the step S104 includes: S301. Search in the third array according to the second offset to obtain the third offset corresponding to the IP address to be queried and the IP information. The IP information includes: longitude and latitude, and postal code. The third offset is used to indicate the position of the first location information of the IP address to be queried in the fourth array, and the first location information is the city information.

[0054] Among them, the content of each array element in the third array includes: longitude and latitude, postal code, and third offset. The third offset can be the array subscript of the array element corresponding to the longitude and latitude and the postal code in the fourth array, and is used to indicate the storage position of the city information corresponding to the longitude and latitude and the postal code in the fourth array.

[0055] Among them, the first location information is the city information. It should be understood that a large city can correspond to multiple longitudes and latitudes and multiple postal codes. Therefore, multiple IP information in the third array can correspond to the same location information in the fourth array.

[0056] It should be noted that the lengths of the postal codes of each city may vary. Therefore, the content of each array element in the third array can sequentially include: longitude and latitude, postal code length, postal code, and third offset. When reading the array element, the number of bytes of the postal code to be read next can be determined according to the read postal code length, and the postal code can be read according to the postal code length, so as to further improve the accuracy of data reading and the flexibility of data storage.

[0057] S302. Search in the fourth array according to the third offset to obtain the fourth offset corresponding to the IP address to be queried and the first position information. The fourth offset is used to indicate the position of the second position information of the IP address to be queried in the fifth array.

[0058] In the fourth array, the array element whose array subscript is equal to the third offset can be used as the array element corresponding to the IP address to be queried in the fourth array, and the content of the array element is read to obtain the fourth offset corresponding to the IP address to be queried and the first position information.

[0059] Optionally, the content of each array element in the fourth array sequentially includes: the length of the city name, the city name, and the fourth offset. The length of the city name is used to indicate the byte position occupied by the city name in the array element. When reading the array element, the number of bytes occupied by the city name can be determined based on the length of the city name first, and the city name can be read according to the length of the city name, and then the fourth offset is read backward.

[0060] Optionally, the fourth offset can be the array subscript of the array element where the second position element corresponding to the first position element is located in the fifth array, and is used to indicate the storage position of the region and country to which the city belongs in the fifth array.

[0061] S303. Search according to the fourth offset and the fifth array to obtain the second position information corresponding to the IP address to be queried. The second position information includes region information and / or country information.

[0062] In the fifth array, the array element whose array subscript is equal to the fourth offset can be used as the array element corresponding to the IP address to be queried in the fifth array, and the content of the array element is read to obtain the second position information corresponding to the IP address to be queried.

[0063] Optionally, the second position information can only include region information, can only include country information, or can include both region information and country information. Among them, the region information can be the province to which the city belongs, and the country information can be the country to which the city and region belong.

[0064] When the second position information includes both country information and region information, the country information and region information can be stored in the same array, or the country information and region information can be stored in two arrays respectively.

[0065] In the first implementation method, the content of each array element in the fifth array sequentially includes: the length of the region name, the region name, the length of the country name, and the country name. Among them, the length of the region name is used to indicate the byte position occupied by the region name in the array element, and the length of the country name is used to indicate the byte position occupied by the country name in the array element. When reading the array element, the number of bytes occupied by the region name can be determined based on the length of the region name first, and the region name can be obtained by reading the array element according to the length of the region name. Then continue to read backward to obtain the length of the country name, and the country name can be obtained by reading the array element according to the length of the country name. At this time, the fourth offset can be the array subscript of the array element where the second position information corresponding to the first position information is located in the fifth array, which is used to indicate the storage position of the region and country to which the city belongs in the fifth array.

[0066] In the second implementation method, the region information can be stored in the fifth array, and the country information can be stored in the next-level array. At this time, each array element in the fifth array includes: region information and an offset value. The offset value is used to indicate the storage position of the country to which the region information belongs in the next-level array. At this time, the at least one IP attribution information array can further include: a third array, a fourth array, a fifth array, and a sixth array.

[0067] Among them, the fifth array stores region information and an offset value, and the sixth array stores country information. Among them, the offset value can be the array subscript in the next-level array, which is used to indicate the storage position of the country information to which the region information belongs in the next-level array.

[0068] Optionally, each array element in the fifth array sequentially stores: the length of the region name, the region name, and the offset value. In the fifth array, the length of the region name in the array element can be read, and the region name can be obtained by reading backward according to the byte length indicated by the length of the region name. Then continue to read to obtain the offset value.

[0069] According to the offset value, the array element at the position indicated by the offset value can be read from the sixth array, and the country information in the array element is used as the country information corresponding to the offset value, and the region information and the country information are used as the second position information.

[0070] Optionally, the content of each array element in the sixth array sequentially includes: the length of the country name and the country name. When reading the country information, the length of the country name can be read first, and the country name can be obtained by reading backward according to the byte length indicated by the length of the country name.

[0071] S304. Generate a query result for the location of the IP address to be queried according to the IP information, the first position information, and the second position information.

[0072] Optionally, the return string format can be set in advance for the location query result, such as "%longitude and latitude%, %postal code%, %city name%, %region name%, %country name%", and the IP information, the first location information, and the second location information are filled into the corresponding positions of the string according to the preset format to obtain the location query result of the IP address to be queried.

[0073] In another implementation, the IP information, the first location information, and the second location information can also be filled into their respective corresponding positions according to the return string format defined by the user to obtain the location query result of the IP address to be queried.

[0074] Next, in combination with Figure 4 the process of querying the location of the IP address 192.168.100.100, the overall process of IP location query in this application will be described. Figure 4 The data contents stored in each array are shown in

[0075] Referring to Figure 4 , the first array can be found based on the first two bytes 192.168, hitting the Figure 4 array element shown, and reading the array element to obtain that there are 1000 IP addresses with the first two bytes being 192.168, and the first offset in the second array is 25000.

[0076] For the array element indicated by the 412038th byte in the second array, reading the array element successively obtains IP information such as "longitude and latitude (120.0898, 30.8707), postal code 313000", and obtains the third offset 87291.

[0077] Search for the array element indicated by the 87291st byte in the fourth array, read the array element to obtain "city name - Huzhou", and obtain the offset of the next-level array "32122".

[0078] Read the array element at the 32122nd byte in the fifth array to obtain "region name - ZheJiang" and the offset "1201" in the next-level array. Finally, search for the array element at the 1201st byte in the sixth array to obtain "country name - China, continent information - Asia". That is, the location query result of the IP address 192.168.100.100 is obtained as "(120.0898, 30.8707), 313000, Huzhou, Zhejiang, China".

[0079] The present application also provides a method for constructing an IP information array. Before querying the location of an IP address based on the IP location query method, the above-mentioned first array, second array, and IP location information array can be constructed first based on the method for constructing an IP information array. The following is a further description of the method for constructing an IP information array, as Figure 5 shown, the method includes: S501. Obtain a first file and a second file. The first file and the second file are associated through an association identifier. The first file includes: an association identifier and multiple address range sets, and each address range set includes multiple IP addresses with the same IP information. The IP information includes: postal code, longitude, and latitude. The second file includes: first location information, second location information, and an association identifier.

[0080] Among them, the content stored in the first file includes: an association identifier, a postal code, longitude, latitude, and an address range set (Classless Inter-Domain Routing, CIDR). Each CIDR includes multiple IP addresses with the same IP information. The IP information included in different CIDRs can be completely different or partially the same. For example, the postal codes and longitude and latitude information of multiple IP addresses are the same, but the IP addresses are different.

[0081] The content stored in the second file includes: first location information, second location information, and an association identifier. The first location information includes: city name, time zone. The second location information includes: area code, province name, continent code, continent name, and country name.

[0082] The association identifier is used to correspond the postal code, longitude and latitude, and CIDR in the first file with the first location information and the second location information in the second file. Exemplarily, the longitude and latitude and the postal code in the first file can indicate a definite location, and have the same association identifier as the combination of the first location information and the second location information including this location in the second file.

[0083] Exemplarily, assume that the longitude and latitude and the postal code in the first file are (120.0898, 30.8707), 313000, and the area indicated is "Huzhou, Zhejiang, China". The association identifier of the IP information "(120.0898, 30.8707), 313000" in the first file is "64785", then the association identifier of the combination of the second location information "Country information - China, Region information - Zhejiang" and the first location information "City information - Huzhou" in the second file is also "64785".

[0084] S502. Construct a first array, a second array, and at least one IP location information array according to the first file and the second file.

[0085] Optionally, based on the IP addresses in the set of address ranges in the first file, a first array and a second array can be constructed. Based on the association identifiers in the first file and the second file, the postal code, longitude and latitude in the first file can be associated with the first location information and the second location information in the second file, and at least one IP attribution information array can be constructed.

[0086] Among them, the postal code, longitude and latitude in the first file, the first location information and the second location information in the second file can be used as the content of the array elements in the IP attribution information array.

[0087] When multiple IP attribution information arrays are constructed, there is a hierarchical relationship between the IP attribution information arrays, that is, an offset is stored in the array elements of the current IP attribution information array, and the offset is used to indicate the position of the array element corresponding to the array element in the current IP attribution information array in the next-level IP attribution information array.

[0088] It can be understood that taking the IP attribution information array including the third array, the fourth array and the fifth array as an example, the third array in the above steps S201-S204 can be the next level of the second array, the fourth array is the next level of the third array, and the fifth array is the next level of the fourth array. Except for the fifth array, the content of the array elements in the remaining arrays includes partial IP attribution information and the offset indicating the position of the array element in the next-level array.

[0089] The following is a further description of constructing the first array, the second array and at least one IP attribution information array according to the first file and the second file, as Figure 6 shown, the above step S502 includes: S601. Construct multiple IP attribution information arrays according to the first file and the second file, where the IP attribution information arrays are arranged hierarchically in sequence, and the array elements of the IP attribution information array at the upper level include the offsets of the corresponding array elements in the adjacent lower-level IP attribution information array.

[0090] In the first implementation, the multiple IP attribution information arrays include a third array, a fourth array and a fifth array. The fifth array can be constructed according to the second location information in the second file, then the fourth array can be constructed according to the offsets of the array elements in the fifth array and the first location information corresponding to the array elements, and then the third array can be constructed according to the offsets of the array elements in the fourth array and the IP information corresponding to the array elements in the first file, and the third array is used as the IP attribution information array at the topmost level.

[0091] In the second implementation method, the multiple IP attribution information arrays include a third array, a fourth array, a fifth array, and a sixth array. At this time, the sixth array can be constructed according to the country information in the second location information, the fifth array can be constructed according to the offsets of the array elements in the sixth array and the region information in the second location information corresponding to each array element, the fourth array can be constructed according to the first location information corresponding to each array element in the fifth array and the offsets of each array element, and finally the third array can be constructed according to the offsets of the array elements in the fourth array and the IP information corresponding to each array element in the first file. The third array is used as the IP attribution information array at the topmost level.

[0092] In the third implementation method, the multiple IP attribution information arrays include a third array and a fourth array. At this time, the array elements in the fourth array can be generated according to the first location information and the second location information, and then the third array can be generated according to the offsets of the array elements in the fourth array and the IP information corresponding to each array element.

[0093] S602. Generate a second array according to the offsets of the array elements in the IP attribution information array at the topmost level and the second IP sub-addresses corresponding to the array elements in the IP attribution information array at the topmost level.

[0094] Optionally, the IP attribution information array at the topmost level can be the last generated IP attribution information array, such as the third array in step S601 above.

[0095] The offsets of the array elements in the IP attribution information array at the topmost level can be the positions of the array elements in the IP attribution information array, such as the subscripts of the array elements.

[0096] Optionally, there is a corresponding relationship between the postal codes, longitude and latitude of the array elements in the IP attribution information array at the topmost level and the IP addresses. Therefore, the array subscripts of the array elements containing postal codes, longitude and latitude can be used as the offsets of the array elements, and the second IP sub-address and the offset of the IP address are combined to obtain an array element of the second array.

[0097] Among them, the array elements in the second array are arranged in the order of the IP addresses in the address range set, that is, the second IP sub-addresses corresponding to the IP addresses with the same first M bytes are arranged in the order of the sizes of the last N bytes in the second array.

[0098] S603. Generate a first array according to the offsets of the array elements in the second array and the first IP sub-addresses corresponding to the array elements in the second array.

[0099] Optionally, the second IP sub-addresses included in each array element of the second array have a corresponding relationship with the first IP sub-address. The array subscript of each array element in the second array can be used as the offset of the array element, and the first IP sub-address and the offset of the IP address are combined to obtain an array element of the first array.

[0100] As a possible implementation, the last N bytes of multiple IP addresses may have the same first M bytes. Exemplarily, the last two bytes of 192.068.100.100 and 192.168.100.110 are different, but the first two bytes are both "192.168". Therefore, the number of IP addresses with the same first M bytes can be recorded to obtain the number of duplicate IP addresses. The starting position of the second IP sub-address corresponding to the first IP sub-address in the second array is used as the first offset, and the number of duplicate IP addresses, the first IP sub-address, and the first offset are used as an array element in the first array.

[0101] It should be noted that the above steps S601 - S603 only illustrate the construction process of each array in the first implementation manner of the above step S104. It should be understood that when the IP location information stored in the array is different, the construction process of the array will also be different, but the construction idea is basically the same, that is, the position of the array elements at the next level and the partial IP location information corresponding to the current level are saved in the array elements at the current level. The construction process of the array in other implementation manners will not be elaborated in this application.

[0102] The following is a further description of the first implementation manner in the above step S601. At this time, multiple IP location information arrays include a third array, a fourth array, and a fifth array, and the third array is the top - level IP location information array. As Figure 7 shown, the above step S601 includes: S701. Generate a fifth array according to each second position information in the second file.

[0103] It should be noted that there may be redundant data in the second file. For example, the countries and continents corresponding to different cities may be the same. Therefore, the country information and continent information in the second file can be extracted, and the data with the same country name and continent name are extracted as the second position information, and the second position information is used as an array element in the fifth array, where the same second position information is only recorded once.

[0104] S702. Generate a fourth array according to the offsets of each array element in the fifth array and the first position information corresponding to each array element in the fifth array in the second file.

[0105] Optionally, based on the country and continent to which each city belongs, the second location information corresponding to each first location information can be determined, and the array subscript of the array element storing the second location information in the fifth array can be used as the fourth offset of the array element. The fourth offset and the first location information are used as an array element of the fourth array.

[0106] S703. Generate a third array according to the offsets of the array elements in the fourth array, the association identifiers, and the IP information corresponding to the array elements in the fourth array in the first file.

[0107] Optionally, based on the association identifier, the postal code and the longitude and latitude corresponding to each first location information can be determined. Therefore, the array subscript of the array element in the fourth array can be used as the third offset of the array element, and the postal code, the longitude and latitude corresponding to the first location information included in the array element, and the third offset are used as an array element in the third array.

[0108] Among them, the process of generating the fourth array according to the offsets of the array elements in the fifth array and the first location information corresponding to the array elements in the fifth array in the second file specifically includes: Use the positions of the array elements in the fifth array as the offsets of the array elements, and use the offsets of the array elements and the first location information corresponding to the second location information as an array element in the fourth array.

[0109] Optionally, the position of the array element in the fifth array can be the array subscript of the array element in the fifth array. The first location information corresponding to the second location information can be the city information belonging to the region and country indicated by the second location information.

[0110] In the process of generating the fourth array, for the current city information, the length of the city name and the city name can be stored in the array element, and the array subscript of the array element corresponding to the region and country information of the city in the fifth array can be stored in the remaining bytes of the array element, obtaining an array element of the fourth array. After adding all the city information as array elements to the array, the finally obtained array is used as the fourth array.

[0111] The above process of generating the third array according to the offsets of the array elements in the fourth array, the association identifiers, and the IP information corresponding to the array elements in the fourth array in the first file, as Figure 8 shown, includes: S801. According to the association identifier of the array element in the fourth array, determine multiple IP addresses corresponding to the association identifier in the first file, and use the IP information of the multiple IP addresses as the IP information corresponding to the array element in the first file.

[0112] Among them, the associated identifier of the array element can be the associated identifier of the second position information in the fourth array in the second file. The data in the first file and the second file establish a mapping relationship through the associated identifier. Therefore, based on the associated identifier, the city information corresponding to each IP address can be determined.

[0113] Optionally, the multiple IP addresses corresponding to the associated identifier can be the IP addresses that have the same associated identifier as the second position information in the array element. Each IP address can find the IP information of the IP address in the first file.

[0114] S802. Use the position of each array element in the fourth array as the offset of each array element, and use the offset of the array element in the fourth array and the IP information corresponding to the array element in the first file as an array element in the third array.

[0115] Optionally, the IP information can be stored in the bytes of the array element, and the array subscript of the storage position of the second position information corresponding to the IP information in the fourth array can be stored in the remaining bytes of the array element to obtain an array element in the third array. After storing all the IP information in the array element, the obtained array is used as the third array.

[0116] Among them, the postal codes in the IP information may have different lengths. When storing the IP information in the array element, the longitude and latitude can be stored in the array element first, then the length of the postal code can be stored, and then the postal code can be stored in the array element.

[0117] The process of generating the second array according to the offset of each array element in the third array and the second IP sub-address corresponding to each array element in the third array includes: Use the last N bytes of the IP address to which each IP information belongs as the second IP sub-address, use the position of each array element in the third array as the offset of each array element, and use the offset of the array element in the third array and the second IP sub-address as an array element in the second array.

[0118] Optionally, the last N bytes of the IP address can be used as the second IP sub-address and stored in the bytes of the array element, the storage position of the IP information of the IP address to which the second IP sub-address belongs in the third array can be used as the offset, and the offset can be stored in the remaining bytes of the array element to obtain an array element of the second array. After storing the second IP sub-addresses of all IP addresses in the array element, the finally obtained array is used as the second array.

[0119] The following is a further description of generating the first array based on the offsets of the array elements in the second array and the corresponding first IP sub-addresses of the array elements in the second array. The above step S605 includes: Take the first M bytes of the IP address to which each second IP sub-address belongs as the first IP sub-address, take the positions of the array elements in the second array as the offsets of the array elements, and take the offsets of the array elements in the second array and the first IP sub-address as an element in the first array.

[0120] Optionally, the first M bytes of the IP address and the number of IP addresses with the same first M bytes can be stored in the array elements in sequence, and the starting position of the second IP sub-addresses with the same first IP sub-address in the second array can be used as the offset and stored in the array elements to obtain an array element of the first array. After storing the first M bytes of all IP addresses in the array elements, the obtained array is used as the first array.

[0121] Before constructing the first array, the second array, and each IP attribution information array according to the first file and the second file, the first file can also be preprocessed, such as Figure 9 As shown, the preprocessing process includes: S901. Merge the first address range set and the second address range set with the same IP information. The last IP address of the first address range set is the previous adjacent IP address of the second address range set.

[0122] In adjacent address range sets, the end address of the previous address range set is equal to the start address of the next address range set minus one. Therefore, the address range sets with the same IP information can be merged.

[0123] S902. Remove duplicate IP addresses in adjacent address range sets.

[0124] Optionally, an IP address can be included in only one address range set. Therefore, if there are duplicate IP addresses in adjacent address range sets, the duplicate IP addresses need to be deleted.

[0125] S903. If the difference between adjacent IP addresses is not equal to the preset value, fill virtual IP addresses between the adjacent IP addresses.

[0126] Among them, the preset value can be 1. If the difference between adjacent IP addresses is not 1, it means that there is a problem of discontinuous IP addresses. At this time, virtual IP addresses can be filled between the adjacent IP addresses, and the location information is represented by [-1, -1, -1]. When this virtual data is queried, it indicates that the IP return result is empty, so as to ensure the continuity of the IP addresses.

[0127] After data preprocessing, the IP addresses in each address range set in the first file are continuous. Therefore, the end address in each address range set can be removed, thereby reducing the memory occupied by the first file.

[0128] Based on the same inventive concept, an IP address location query device corresponding to the IP address location query method is also provided in an embodiment of the present application. Since the principle of the device in the embodiment of the present application for solving problems is similar to the above IP address location query method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again. The device includes: an acquisition module, a first query module, a second query module, and a third query module.

[0129] The acquisition module is used to acquire a first IP sub-address and a second IP sub-address of the IP address to be queried, where the first IP sub-address is the first M bytes in the IP address to be queried, and the second IP sub-address is the last N bytes in the IP address to be queried, and both M and N are integers greater than 0.

[0130] The first query module is used to find the first array element containing the first IP sub-address in the first array, and obtain the first offset in the first array element; The second query module is used to use the first offset as the starting search position of the second array, find the second array element containing the second IP sub-address in the second array, and obtain the second offset in the second array element, where the second offset is used to indicate the starting storage position of the location information of the IP address to be queried in the IP location information array; The third query module is used to query and obtain the location query result of the IP address to be queried according to the second offset and at least one IP location information array.

[0131] Optionally, at least one IP location information array includes: a third array, a fourth array, and a fifth array; The third query module is specifically used for: Search in the third array according to the second offset to obtain the third offset corresponding to the IP address to be queried and the IP information. The IP information includes: longitude and latitude, and postal code. The third offset is used to indicate the position of the first location information of the IP address to be queried in the fourth array, and the first location information is city information; Search in the fourth array according to the third offset to obtain the fourth offset corresponding to the IP address to be queried and the first location information. The fourth offset is used to indicate the position of the second location information of the IP address to be queried in the fifth array; Search and obtain the second location information corresponding to the IP address to be queried according to the fourth offset and the fifth array. The second location information includes region information and / or country information; Generate the query result of the location of the IP address to be queried based on the IP information, the first location information, and the second location information.

[0132] Based on the same inventive concept, an apparatus for constructing an IP information array corresponding to the method for constructing an IP information array is further provided in the embodiments of the present application. Since the principle of problem-solving of the apparatus in the embodiments of the present application is similar to that of the above-mentioned method for constructing an IP information array in the embodiments of the present application, the implementation of the apparatus can refer to the implementation of the method, and the repeated parts will not be elaborated. The apparatus includes: a file acquisition module and an array construction module.

[0133] Optionally, the array construction module is specifically configured to: Construct a plurality of IP location information arrays according to the first file and the second file, where each IP location information array is arranged hierarchically in sequence, and the array elements of the IP location information array in the upper level include the offsets of the corresponding array elements in the adjacent lower-level IP location information array; Generate a second array according to the offsets of the array elements in the IP location information array of the topmost level and the second IP sub-addresses corresponding to the array elements in the IP location information array of the topmost level; Generate a first array according to the offsets of the array elements in the second array and the first IP sub-addresses corresponding to the array elements in the second array.

[0134] Optionally, the plurality of IP location information arrays include a third array, a fourth array, and a fifth array, and the third array is the IP location information array of the topmost level; Optionally, the array construction module is further configured to: Generate a fifth array according to each second location information in the second file; Generate a fourth array according to the offsets of the array elements in the fifth array and the first location information corresponding to the array elements in the fifth array in the second file; Generate a third array according to the offsets of the array elements in the fourth array, the association identifier, and the IP information corresponding to the array elements in the fourth array in the first file.

[0135] Optionally, the array construction module is further configured to: Use the positions of the array elements in the fifth array as the offsets of the array elements, and use the offsets of the array elements and the first location information corresponding to the second location information as an array element in the fourth array.

[0136] Optionally, the array construction module is further configured to: Determine multiple IP addresses corresponding to the association identifier in the first file according to the association identifier of the array elements in the fourth array, and use the IP information of the multiple IP addresses as the IP information corresponding to the array elements in the first file; Use the position of each array element in the fourth array in the fourth array as the offset of each array element, and use the offset of the array elements in the fourth array and the IP information corresponding to the array elements in the first file as an array element in the third array.

[0137] Optionally, the array construction module is further configured to: Use the last N bytes of the IP address to which each IP information belongs as the second IP sub-address, use the position of each array element in the third array in the third array as the offset of each array element, and use the offset of the array elements in the third array and the second IP sub-address as an array element in the second array.

[0138] Optionally, the array construction module is specifically configured to: Use the first M bytes of the IP address to which each second IP sub-address belongs as the first IP sub-address, use the position of each array element in the second array in the second array as the offset of each array element, and use the offset of the array elements in the second array and the first IP sub-address as an array element in the first array.

[0139] Optionally, the array construction module is specifically configured to: Perform a merging process on the first address range set and the second address range set with the same IP information, where the last IP address of the first address range set is the previous adjacent IP address of the second address range set; Perform a deduplication process on the same IP addresses in the adjacent address range sets; If the difference between adjacent IP addresses is not equal to the preset value, fill in virtual IP addresses between the adjacent IP addresses.

[0140] Figure 10 The figure shows a schematic structural diagram of an electronic device provided by an embodiment of the present application, including: a processor 1001, a storage medium 1002, and a bus 1003. The storage medium 1002 stores machine-readable instructions executable by the processor 1001. When the electronic device runs an IP location query method as in the embodiment, the processor 1001 communicates with the storage medium 1002 through the bus 1003, and the processor 1001 executes the machine-readable instructions, the preamble part of the method item of the processor 1001, to execute the steps of the IP location query method.

[0141] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the processor executes the steps of the IP address location query method.

[0142] In the embodiment of the present application, when the computer program is run by a processor, it can also execute other machine-readable instructions to execute the methods described in other embodiments. For the specific method steps and principles, refer to the description of the embodiments, and details are not elaborated here.

[0143] In the embodiments provided by the present application, it should be understood that the disclosed device and method can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some communication interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0144] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0145] In addition, each functional unit in the embodiments provided by the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.

[0146] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0147] It should be noted that like reference numerals and letters indicate like items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used for descriptive distinction and should not be construed as indicating or implying relative importance.

[0148] Finally, it should be noted that the above-described embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, rather than limiting it. The protection scope of the present application is not limited thereto. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present application can still modify the technical solutions recorded in the foregoing embodiments or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. All should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A method for querying IP location, characterized in that: include: Obtain a first IP sub-address and a second IP sub-address of the IP address to be queried, wherein the first IP sub-address is the first M bytes of the IP address to be queried, and the second IP sub-address is the last N bytes of the IP address to be queried, and M and N are both integers greater than 0; Find a first array element containing the first IP sub-address in the first array, and obtain a first offset in the first array element; Using the first offset as the starting search position of the second array, searching for a second array element containing the second IP sub-address in the second array, and obtaining a second offset in the second array element, wherein the second offset is used to indicate the starting storage position of the location information of the IP address to be queried in the IP location information array; According to the second offset and at least one IP attribution information array, the attribution query result of the IP address to be queried is obtained.

2. The method according to claim 1, characterized in that The at least one IP attribution information array includes: a third array, a fourth array, and a fifth array; The querying and obtaining the location query result of the IP address to be queried according to the second offset and the plurality of IP location information arrays includes: Searching in the third array according to the second offset, obtaining a third offset and IP information corresponding to the IP address to be queried, wherein the IP information includes: longitude and latitude, and a postal code, and the third offset is used to indicate the position of the first location information of the IP address to be queried in the fourth array, wherein the first location information is city information; Searching in the fourth array according to the third offset to obtain a fourth offset and first position information corresponding to the IP address to be queried, wherein the fourth offset is used to indicate a position of the second position information of the IP address to be queried in the fifth array; According to the fourth offset and the fifth array, second location information corresponding to the IP address to be queried is searched and obtained, where the second location information includes region information and / or country information; Generate a location query result of the IP address to be queried based on the IP information, the first location information and the second location information.

3. A method for constructing an IP information array, characterized in that: include: Acquire a first file and a second file, wherein the first file and the second file are associated with each other through an association identifier, wherein the first file includes: an association identifier and a plurality of address range sets, each of the address range sets includes a plurality of IP addresses with the same IP information, wherein the IP information includes: a postal code, and longitude and latitude, and the second file includes: first location information, second location information, and the association identifier; A first array, a second array and at least one IP attribution information array are constructed according to the first file and the second file.

4. The method according to claim 3, characterized in that The at least one IP attribution information array includes a plurality of IP attribution information arrays, and the first array, the second array, and the at least one IP attribution information array are constructed according to the first file and the second file, including: Constructing a plurality of IP attribution information arrays according to the first file and the second file, wherein each of the IP attribution information arrays is arranged in order according to a hierarchy, and an array element of an IP attribution information array of an upper level includes an offset of a corresponding array element in an IP attribution information array of an adjacent lower level; Generate a second array according to the offset of each array element in the IP attribution information array of the uppermost level and the second IP sub-address corresponding to each array element in the IP attribution information array of the uppermost level; A first array is generated according to the offset of each array element in the second array and the first IP sub-address corresponding to each array element in the second array.

5. The method according to claim 4, characterized in that The plurality of IP attribution information arrays include a third array, a fourth array, and a fifth array, wherein the third array is an IP attribution information array of the top level; The step of constructing at least one IP attribution information array according to the first file and the second file includes: Generate a fifth array according to each of the second position information in the second file; Generate a fourth array according to the offset of each array element in the fifth array and the first position information corresponding to each array element in the fifth array in the second file; A third array is generated according to the offset of each array element in the fourth array, the association identifier, and the IP information corresponding to each array element in the fourth array in the first file.

6. The method according to claim 5, characterized in that Generating a fourth array according to the offset of each array element in the fifth array and the first position information corresponding to each array element in the fifth array in the second file includes: The position of each array element in the fifth array is used as the offset of each array element, and the first position information corresponding to the offset of each array element and the second position information is used as an array element in the fourth array.

7. The method according to claim 5, characterized in that The generating a third array according to the offset of each array element in the fourth array, the association identifier, and the IP information corresponding to each array element in the fourth array in the first file comprises: According to the association identifier of the array element in the fourth array, determine in the first file a plurality of IP addresses corresponding to the association identifier, and use the IP information of the plurality of IP addresses as the IP information corresponding to the array element in the first file; The position of each array element in the fourth array is used as the offset of each array element, and the offset of the array element in the fourth array and the IP information corresponding to the array element in the first file are used as an array element in the third array.

8. The method according to claim 5, characterized in that The generating of the second array according to the offset of each array element in the IP attribution information array of the uppermost level and the second IP sub-address corresponding to each array element in the IP attribution information array comprises: The last N bytes of the IP address to which each IP information belongs are used as the second IP sub-address, the position of each array element in the third array is used as the offset of each array element, and the offset of the array element in the third array and the second IP sub-address are used as an array element in the second array.

9. The method according to claim 4, characterized in that The generating the first array according to the offset of each data in the second array and the first IP sub-address corresponding to each data in the second array comprises: The first M bytes of the IP address to which each of the second IP sub-addresses belongs are used as the first IP sub-address, the position of each array element in the second array is used as the offset of each array element, and the offset of the array element in the second array and the first IP sub-address are used as an array element in the first array.

10. The method according to claim 3, characterized in that: Before constructing the first array, the second array and at least one IP attribution information array according to the first file and the second file, the method further includes: Merging a first address range set and a second address range set with the same IP information, wherein the last IP address of the first address range set is the previous adjacent IP address of the second address range set; De-duplicate the same IP addresses in a set of adjacent address ranges; If the difference between adjacent IP addresses is not equal to the preset value, a virtual IP address is filled between the adjacent IP addresses.

11. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to execute the IP location query method as described in claim 1 or 2, or the steps of the IP information array construction method as described in any one of claims 3-10.

Citation Information

Patent Citations

  • Geographic position information index establishment and information query method and electronic equipment

    CN111797180A

  • Data storage method and device, data query method and device and electronic equipment

    CN114265787A

  • IP address processing method and device, and storage medium

    CN114285797A