Internet Protocol (IP) address library construction method and device
By building an IP address library, using integer data types and home encoding tables, the problems of large storage space and low query efficiency caused by unreasonable storage structure of traditional IP address library are solved, and smaller storage space and higher query efficiency.
Patent Information
- Application Number
- CN202410165443.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-05
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-02-05
AI Technical Summary
There is an unreasonable storage structure during the construction of traditional IP address library, which causes large storage space to be occupied, affecting query efficiency and application performance.
By obtaining the IP list, we build an IP address library, including the target file and the home encoding table, and use the integer data type to store the IP and home encoding results, avoid directly saving the address information of the string type, and confronting adjacent characters during the construction process. IPs are aggregated and only the last IP of the continuous IP and the home encoding result are stored.
It effectively reduces the size of the IP address library file, improves storage efficiency and query efficiency, and solves the problem of the traditional IP address library taking up a large storage space.
Smart Images

Figure CN118158292B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for constructing an IP address library. Background Art
[0002] Currently, there are many services on the Internet that query the attribution information based on the Internet Protocol (IP) address database. For example, social media and other services have recently been forced to display the user's IP location, or weather forecasts provide accurate weather forecast queries based on IP location. The above services all need to query the attribution information corresponding to a certain IP address, such as country information, province information, and city information.
[0003] In the related art, the storage structure of the traditional IP address library is unreasonable, resulting in a large amount of storage space being occupied. Therefore, how to effectively construct an IP address library is a technical problem that those skilled in the art need to solve urgently. Summary of the invention
[0004] In view of the problems in the prior art, an embodiment of the present invention provides a method and device for constructing an Internet Protocol (IP) address library.
[0005] Specifically, the embodiment of the present invention provides the following technical solutions:
[0006] In a first aspect, an embodiment of the present invention provides a method for constructing an IP address library, comprising:
[0007] Obtain an Internet Protocol IP list; the IP list includes multiple IPs;
[0008] According to the multiple IPs in the IP list, an IP address library is constructed; the IP address library includes a target file and a location code table; wherein,
[0009] The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int;
[0010] The place of origin coding table includes the corresponding relationship between the place of origin and the coding result.
[0011] Further, the step of constructing an IP address library according to the multiple IPs in the IP list includes:
[0012] Determine the location corresponding to each IP in the IP list;
[0013] The encoding results of each IP and the location corresponding to each IP are stored in the target file in the IP address library.
[0014] Further, the step of constructing an IP address library according to the multiple IPs in the IP list includes:
[0015] Arrange multiple IPs in the IP list in ascending order to obtain a target IP list; the target IP list is the IP list in ascending order;
[0016] In the case where the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the second IP and the location corresponding to the second IP is abandoned to be stored in the target file in the IP address library; the first IP and the second IP are two adjacent IPs in the target IP list; the value of the first IP is less than the value of the second IP;
[0017] When the place of attribution corresponding to the second IP in the target IP list is different from the place of attribution corresponding to the first IP, the encoding result of the first IP and the place of attribution corresponding to the first IP are stored in the target file in the IP address library, and the value of the first element in the target file is increased by 1.
[0018] Furthermore, the attribution code table includes at least one of the following:
[0019] Country code table, province code table, city code table and region code table.
[0020] Furthermore, the location information in the location coding table may be in any one or more language formats.
[0021] Furthermore, after constructing the IP address library, the method further includes:
[0022] Get the IP to be queried;
[0023] According to the IP to be queried and the IP address library, the location corresponding to the IP to be queried is obtained.
[0024] Further, obtaining the location corresponding to the IP to be queried according to the IP to be queried and the IP address library includes:
[0025] Matching the IP to be queried with the second element in the target file in the IP address library to determine the encoding result of the home location corresponding to the IP to be queried;
[0026] The coding result of the place of origin corresponding to the IP to be queried is associated with the place of origin coding table in the IP address library to obtain the place of origin corresponding to the IP to be queried.
[0027] In a second aspect, an embodiment of the present invention further provides an IP address library construction device, comprising:
[0028] An acquisition module is used to acquire an Internet Protocol IP list; the IP list contains multiple IPs;
[0029] A construction module is used to construct an IP address library according to the multiple IPs in the IP list; the IP address library includes a target file and a location code table; wherein,
[0030] The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int;
[0031] The place of origin coding table includes the corresponding relationship between the place of origin and the coding result.
[0032] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the IP address library construction method described in the first aspect are implemented.
[0033] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the IP address library construction method described in the first aspect are implemented.
[0034] In a fifth aspect, an embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the IP address library construction method as described in the first aspect.
[0035] The Internet Protocol IP address library construction method and device provided by the embodiment of the present invention, after obtaining the IP list, construct the IP address library according to multiple IPs in the IP list; wherein the IP address library includes a target file and a location coding table, and the location information corresponding to each IP can be quickly obtained by matching the location coding result with the location coding table. Moreover, since the data format in the IP address library is integer, the direct storage of address information of the string type is avoided. The constructed IP address library file occupies less space and has higher storage efficiency, thereby effectively solving the problem of the existing IP address library occupying a large storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 This is one of the flow diagrams of the method for constructing an IP address library provided by an embodiment of the present invention;
[0038] Figure 2 This is one of the schematic diagrams of the IP address library structure provided by an embodiment of the present invention;
[0039] Figure 3 This is the second schematic diagram of the IP address library structure provided by the embodiment of the present invention;
[0040] Figure 4 This is the third schematic diagram of the IP address library structure provided by the embodiment of the present invention;
[0041] Figure 5 This is a second flow chart of the method for constructing an IP address database provided by an embodiment of the present invention;
[0042] Figure 6 This is a third flow chart of the method for constructing an IP address library provided by an embodiment of the present invention;
[0043] Figure 7 It is one of the schematic diagrams of the coding table provided in the embodiment of the present invention;
[0044] Figure 8 2 is a schematic diagram of a coding table provided in an embodiment of the present invention;
[0045] Fig. 9 It is a schematic diagram of the structure of an IP address library construction device provided by an embodiment of the present invention;
[0046] Fig.10 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] The method of the embodiment of the present invention can be applied to the scenario of constructing an IP address library, and can effectively solve the problem that the existing IP address library occupies a large storage space.
[0049] In the related art, the storage structure of the traditional IP address library is unreasonable, resulting in a large amount of storage space being occupied. Therefore, how to effectively construct an IP address library is a technical problem that those skilled in the art need to solve urgently.
[0050] The IP address library construction method of the embodiment of the present invention, after obtaining the IP list, constructs the IP address library according to multiple IPs in the IP list; wherein the IP address library includes a target file and a location coding table, and the location information corresponding to each IP can be quickly obtained by matching the location coding result with the location coding table. Moreover, since the data format in the IP address library is integer, direct storage of address information of string type is avoided. The constructed IP address library file occupies less space and has higher storage efficiency, thereby effectively solving the problem of large storage space occupied by the existing IP address library.
[0051] Combine the following Figure 1-Figure 10 The technical solution of the present invention is described in detail with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0052] Figure 1 1 is a flow chart of an embodiment of a method for constructing an IP address database provided by an embodiment of the present invention. Figure 1 As shown, the method provided in this embodiment includes:
[0053] Step 101, obtaining an Internet Protocol IP list; the IP list includes multiple IPs;
[0054] Specifically, in the field of network security, the construction of IP address database is crucial because it directly involves the analysis of network traffic, anomaly detection, and identification of potential threats. As a key network resource, IP address database is widely used in network traffic analysis, security monitoring, user positioning and other fields. The following problems exist in the construction process of traditional IP address database: low efficiency in processing large-scale IP address data, resulting in a long construction process; unreasonable storage structure of IP address database, resulting in large storage space, which is not conducive to application in resource-limited environments; IP address database files are too large and have poor performance in actual queries, affecting the real-time performance of related applications.
[0055] In order to solve the above problem, in the embodiment of the present application, an IP list is first obtained; wherein the IP list may include tens of thousands of IPs to be stored.
[0056] Step 102: construct an IP address library based on multiple IPs in the IP list; the IP address library includes a target file and a location code table; wherein,
[0057] The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int;
[0058] The place of origin coding table includes the correspondence between the place of origin and the coding results.
[0059] Specifically, after obtaining the IP list, in an embodiment of the present application, an IP address library is constructed based on all IPs in the IP list.
[0060] Optionally, the IP address library constructed in the embodiment of the present application includes a target file and a location code table; wherein the storage structure of the target file is as follows: Figure 2 As shown, it includes a first element hdr and multiple second elements hint; wherein the first element hdr is used to indicate the number of second elements hint in the IP address library; the second element is used to store the encoding results of the target IP and the location corresponding to the target IP; wherein the target IP is any IP in the IP list.
[0061] Optionally, the first element hdr is stored in Figure 3 In the hdr structure shown in the figure, the second element hint is stored in Figure 4 In the hint structure shown. Optionally, the data type of the first element hdr stored in the hdr structure is an integer, and the encoding results of the target IP and the place of origin corresponding to the target IP in the second element hint stored in the hint structure are also integers, thereby avoiding directly saving the address information of the string type, which can effectively save storage space compared to the storage format of the string in the prior art.
[0062] Optionally, the location coding table in the embodiment of the present application includes the correspondence between the location and the coding result, and then according to the coding result of the location corresponding to the target IP in the first element hint and the location coding table, the location corresponding to the target IP in the first element hint can be determined. Therefore, only integer type data can be stored in the target file without storing string type address information, and the location corresponding to the IP can be obtained.
[0063] That is, in the embodiment of the present application, the IP address library file is no longer a file, but is composed of a target file and a location code table. Moreover, when the IP address library is constructed, the existing string type address is converted into an integer code for storage, and the IP address library file is stored as a binary structure defined by a specific data structure, thereby effectively reducing the file size of the IP address library and avoiding directly saving string type address information.
[0064] It should be noted that (1) in the storage structure of the IP address library in the embodiment of the present application, the data types corresponding to the first element and the second element are both integers, which takes up less space; (2) the IP address library of the present application does not need to store address information of the string type, but obtains the location information corresponding to each IP by matching the location coding result with the location coding table. Therefore, the technical concept of the construction of the IP address library in the present application is also different from the technical concept of the IP address library in the prior art. (3) The IP address library of the present application only contains the target IP, the location coding result corresponding to the target IP, and the location coding table. There is no location information in the form of a string, and there is no other redundant information such as longitude and latitude. Therefore, the space occupied is also reduced accordingly, which can effectively solve the problem of unreasonable storage structure of the IP address library in the construction process of the traditional IP address library in the prior art, resulting in a large amount of storage space occupied.
[0065] The method of the above embodiment, after obtaining the IP list, constructs an IP address library according to multiple IPs in the IP list; wherein the IP address library includes a target file and a location coding table, and the location information corresponding to each IP can be quickly obtained by matching the location coding result with the location coding table. Moreover, since the data format in the IP address library is integer, direct storage of address information of string type is avoided. The constructed IP address library file occupies less space and has higher storage efficiency, thereby effectively solving the problem of large storage space occupied by the existing IP address library.
[0066] In one embodiment, an IP address library is constructed based on multiple IPs in an IP list, including:
[0067] Determine the location corresponding to each IP in the IP list;
[0068] The encoding results of each IP and the location corresponding to each IP are stored in the target file in the IP address library.
[0069] Specifically, after obtaining the IP list, the embodiment of the present application first determines the location corresponding to each IP in the IP list; optionally, each IP in the IP list can be matched with an existing IP address library to obtain the location corresponding to each IP in the IP list. Further, according to the location corresponding to each IP in the IP list and the location coding table, the location coding result corresponding to each IP can be obtained; and then the coding results of each IP and the location corresponding to each IP can be stored in the target file in the IP address library.
[0070] The method of the above embodiment stores the coding results of each IP in the IP list and the location corresponding to each IP in the target file in the IP address library. Then, in the process of IP location query, the location information corresponding to each IP can be quickly obtained based on the matching of the location coding results and the location coding table, thereby avoiding the direct storage of string type address information. While saving the storage space of the IP address library, it can also effectively improve the efficiency of IP location query.
[0071] In one embodiment, an IP address library is constructed based on multiple IPs in an IP list, including:
[0072] Arrange multiple IPs in the IP list in ascending order to obtain a target IP list; the target IP list is the IP list in ascending order;
[0073] If the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the second IP and the location corresponding to the second IP is abandoned and stored in the target file in the IP address library; the first IP and the second IP are two adjacent IPs in the target IP list; the value of the first IP is less than the value of the second IP;
[0074] If the place of attribution corresponding to the second IP in the target IP list is different from the place of attribution corresponding to the first IP, the encoding result of the first IP and the place of attribution corresponding to the first IP are stored in the target file in the IP address library, and the value of the first element in the target file is increased by 1.
[0075] Specifically, in the process of constructing the IP address library, the embodiment of the present application can also arrange multiple IPs in the IP list in ascending order to obtain a target IP list; and when the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the first IP and the location corresponding to the first IP is abandoned and stored in the target file in the IP address library; when the location corresponding to the second IP in the target IP list is different from the location corresponding to the first IP, the encoding result of the first IP and the location corresponding to the first IP is stored in the target file in the IP address library. That is, when the locations corresponding to the first IP and the second IP are the same, the first IP and the second IP are aggregated, the first IP is not stored, and it is further determined whether the locations corresponding to the second IP and the third IP are the same. If they are still the same, the second IP and the third IP are continued to be aggregated, and the second IP is not stored; if the locations corresponding to the second IP and the third IP are different, the second IP and the location encoding result corresponding to the second IP are stored. By analogy, adjacent IPs with the same location are aggregated, and adjacent IPs with different locations are stored. Therefore, in the case of consecutive IPs belonging to the same location, only the last IP in the consecutive IPs and the corresponding location encoding result are stored, while other IPs in the consecutive IPs are not stored, thereby effectively reducing the size of the target file in the IP address library, further saving the storage space and query efficiency of the IP address library.
[0076] For example, Figure 5 and Figure 6 As shown, if the encoding results of the locations corresponding to IP 1.1.1.2 and IP 1.1.1.3 are the same, IP 1.1.1.2 and IP 1.1.1.3 are aggregated and IP 1.1.1.2 is not stored. If the encoding results of the locations corresponding to IP 1.1.1.3 and IP 1.1.1.4 are different, IP 1.1.1.3 and the encoding results of the corresponding locations are stored, thereby effectively reducing the size of the target file in the IP address library and saving the storage space of the IP address library.
[0077] The method of the above embodiment aggregates adjacent IPs with the same location and stores adjacent IPs with different locations, so that in the case of consecutive IPs belonging to the same location, only the last IP in the consecutive IPs and the corresponding location coding result are stored, while other IPs in the consecutive IPs are not stored, thereby effectively reducing the size of the target file in the IP address library, further saving the storage space and query efficiency of the IP address library.
[0078] In one embodiment, the location code table includes at least one of the following:
[0079] Country code table, province code table, city code table and region code table.
[0080] Specifically, in the embodiment of the present application, the location code table includes a country code table, a province code table, a city code table and a region code table, so that the location information corresponding to the IP address can be displayed in different dimensions and with different accuracy through various types of code tables, thereby meeting the requirements of different scenarios and improving the application scenarios of the IP address library. For example, the country code table and the province code table are as follows: Figure 7 and Figure 8 shown.
[0081] For example, when the location code table only includes the country code table, the location corresponding to the IP can be quickly queried. When the location code table includes the country code table, the province code table, the city code table and the region code table, the location information corresponding to the IP can be displayed more accurately, so that the location code table can meet the needs of different scenarios.
[0082] In one embodiment, the location information in the location coding table may be in any one or more language formats.
[0083] Specifically, the location information in the location code table in the embodiment of the present application can be in any one or more language formats, so that the IP location query results in the language format corresponding to the query personnel in different regions can be adaptively displayed, so that the query personnel can obtain the IP location information comprehensively, conveniently, quickly and accurately. This optimized design not only provides fast matching, but also provides an ideal solution for user customized translation needs and efficient use of storage resources, effectively provides a flexible location translation solution, and provides more flexible customization options for multi-language translation.
[0084] In one embodiment, after building the IP address library, the method further includes:
[0085] Get the IP to be queried;
[0086] According to the IP to be queried and the IP address database, the location corresponding to the IP to be queried is obtained.
[0087] Specifically, after constructing the IP address library, the constructed IP address library can be used to query the IP's place of origin. Optionally, after obtaining the IP to be queried, the IP to be queried and the IP address library can be matched to obtain the place of origin corresponding to the IP to be queried. Optionally, since the storage space in the IP address library in the present application is smaller than the storage space of the IP address library in the prior art, and the IP address and the data format of the IP address in the IP address library in the present application are both integers, compared to the IP address and the place of origin of the IP address in the IP address library in the prior art, which are both in string format, the query result of the place of origin corresponding to the IP can be obtained more quickly. Moreover, when querying the IP's place of origin, only the target file in the IP address library can be loaded, and the place of origin address can be converted into a string type through the place of origin coding table when rendering the page, which can effectively reduce memory consumption and improve the efficiency of IP place of origin query.
[0088] In one embodiment, obtaining the location corresponding to the IP to be queried according to the IP to be queried and the IP address library includes:
[0089] Match the IP to be queried with the second element in the target file in the IP address library to determine the encoding result of the home location corresponding to the IP to be queried;
[0090] The coding result of the location corresponding to the IP to be queried is associated with the location coding table in the IP address library to obtain the location corresponding to the IP to be queried.
[0091] Specifically, when the embodiment of the present application performs an IP attribution query based on the IP address library, the second element hint in the target file in the IP address library can be matched first, so that the encoding result of the attribution corresponding to the IP to be queried can be determined according to the matched IP, and then the encoding result of the attribution corresponding to the IP to be queried is associated with the attribution encoding table in the IP address library, and the attribution corresponding to the IP to be queried can be obtained. It should be noted that the IP address library in the present application does not include the attribution information in the form of a string corresponding to each IP, but obtains the attribution information corresponding to the IP to be queried by matching the attribution encoding result with the attribution encoding table. Therefore, the technical concept of the IP address library construction in the present application is also different from the technical concept of the IP address library in the prior art. In addition, since the storage space in the IP address library in the present application is smaller than the storage space of the IP address library in the prior art, and the data format of the IP address and the encoding result of the IP address attribution in the IP address library in the present application are both integers, compared with the IP address and the attribution of the IP address in the IP address library in the prior art, the query result of the attribution corresponding to the IP can be obtained more quickly. Moreover, when performing an IP location query, you can only load the target file in the IP address library, and convert it into a string type location address through the location encoding table when rendering the page, which can reduce memory consumption and improve the efficiency of IP location query.
[0092] The method of the above embodiment not only uses an efficient code encoding mechanism in the IP query and matching process, thereby significantly improving the matching speed; but also avoids directly saving string-type address information, so that the constructed IP address library file is extremely small, which not only helps to improve storage and query efficiency, but also does not damage the accuracy of address information; and when performing IP attribution query, only the target file in the IP address library can be loaded, and the attribution address of the string type is converted through the attribution coding table when rendering the page, thereby reducing the memory consumption when loading the IP address library and improving the speed of IP matching attribution.
[0093] The IP address library construction device provided by the present invention is described below. The IP address library construction device described below and the IP address library construction method described above can be referenced to each other.
[0094] Fig. 9 : is a schematic diagram of the structure of the IP address library construction device provided by the present invention. The IP address library construction device provided in this embodiment includes:
[0095] Acquisition module 910, used to acquire an Internet Protocol IP list; the IP list contains multiple IPs;
[0096] The construction module 920 is used to construct an IP address library according to the multiple IPs in the IP list; the IP address library includes a target file and a location code table; wherein,
[0097] The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int;
[0098] The place of origin coding table includes the correspondence between the place of origin and the coding results.
[0099] Optionally, the construction module 920 is specifically used to: determine the location corresponding to each IP in the IP list;
[0100] The encoding results of each IP and the location corresponding to each IP are stored in the target file in the IP address library.
[0101] Optionally, the construction module 920 is specifically used to: arrange multiple IPs in the IP list in ascending order to obtain a target IP list; the target IP list is the IP list arranged in ascending order;
[0102] If the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the second IP and the location corresponding to the second IP is abandoned and stored in the target file in the IP address library; the first IP and the second IP are two adjacent IPs in the target IP list; the value of the first IP is less than the value of the second IP;
[0103] If the place of attribution corresponding to the second IP in the target IP list is different from the place of attribution corresponding to the first IP, the encoding result of the first IP and the place of attribution corresponding to the first IP are stored in the target file in the IP address library, and the value of the first element in the target file is increased by 1.
[0104] Optionally, the attribution code table includes at least one of the following:
[0105] Country code table, province code table, city code table and region code table.
[0106] Optionally, the construction module 920 is further used to: obtain the IP to be queried;
[0107] According to the IP to be queried and the IP address database, the location corresponding to the IP to be queried is obtained.
[0108] Optionally, the construction module 920 is further used to: match the IP to be queried with the second element in the target file in the IP address library to determine the encoding result of the home address corresponding to the IP to be queried;
[0109] The coding result of the location corresponding to the IP to be queried is associated with the location coding table in the IP address library to obtain the location corresponding to the IP to be queried.
[0110] The device of the embodiment of the present invention is used to execute the method in any of the aforementioned method embodiments. Its implementation principle and technical effects are similar and will not be repeated here.
[0111] Fig.10 An example of a physical structure diagram of an electronic device is provided, and the electronic device may include: a processor 1010, a communication interface 1020, a memory 1030, and a communication bus 1040, wherein the processor 1010, the communication interface 1020, and the memory 1030 communicate with each other through the communication bus 1040. The processor 1010 may call the logic instructions in the memory 1030 to execute the IP address library construction method, and the method includes: obtaining an Internet Protocol IP list; the IP list includes multiple IPs; according to the multiple IPs in the IP list, an IP address library is constructed; the IP address library includes a target file and a home location coding table; wherein the target file includes a first element and multiple second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the target IP and the coding result of the home location corresponding to the target IP; the data types of the target IP and the coding result are integer int; the home location coding table includes the corresponding relationship between the home location and the coding result.
[0112] In addition, the logic instructions in the above-mentioned memory 1030 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0113] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the IP address library construction method provided by the above methods, and the method includes: obtaining an Internet Protocol IP list; the IP list contains multiple IPs; according to the multiple IPs in the IP list, an IP address library is constructed; the IP address library includes a target file and an attribution coding table; wherein the target file includes a first element and multiple second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the target IP and the coding result of the attribution corresponding to the target IP; the data type of the target IP and the coding result is integer int; the attribution coding table includes the correspondence between the attribution and the coding result.
[0114] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the above-mentioned IP address library construction method, the method comprising: obtaining an Internet Protocol IP list; the IP list comprises multiple IPs; based on the multiple IPs in the IP list, constructing an IP address library; the IP address library comprises a target file and a location coding table; wherein the target file comprises a first element and multiple second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the target IP and the coding result of the location corresponding to the target IP; the data types of the target IP and the coding result are integer int; the location coding table comprises the correspondence between the location and the coding result.
[0115] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0116] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0117] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for constructing an IP address library, characterized in that: include: Obtain an Internet Protocol IP list; the IP list includes multiple IPs; Building an IP address library according to the multiple IPs in the IP list; The IP address library includes a target file and a location code table; wherein, The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int; The attribution coding table includes the corresponding relationship between the attribution and the coding result; The step of constructing an IP address library according to the plurality of IPs in the IP list comprises: Arrange multiple IPs in the IP list in ascending order to obtain a target IP list; the target IP list is the IP list in ascending order; In the case where the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the second IP and the location corresponding to the second IP is abandoned to be stored in the target file in the IP address library; the first IP and the second IP are two adjacent IPs in the target IP list; the value of the first IP is less than the value of the second IP; When the place of attribution corresponding to the second IP in the target IP list is different from the place of attribution corresponding to the first IP, the encoding result of the first IP and the place of attribution corresponding to the first IP are stored in the target file in the IP address library, and the value of the first element in the target file is increased by 1.
2. The method for constructing an IP address library according to claim 1, characterized in that: The step of constructing an IP address library according to the plurality of IPs in the IP list comprises: Determine the location corresponding to each IP in the IP list; The encoding results of each IP and the location corresponding to each IP are stored in the target file in the IP address library.
3. The method for constructing an IP address library according to claim 1, characterized in that: The attribution code table includes at least one of the following: Country code table, province code table, city code table and region code table.
4. The method for constructing an IP address library according to claim 1, characterized in that: The location information in the location coding table may be in any one or more language formats.
5. The method for constructing an IP address library according to any one of claims 1 to 4, characterized in that: After building the IP address library, it also includes: Get the IP to be queried; According to the IP to be queried and the IP address library, the location corresponding to the IP to be queried is obtained.
6. The method for constructing an IP address library according to claim 5, characterized in that: The obtaining, according to the IP to be queried and the IP address library, the location corresponding to the IP to be queried includes: Matching the IP to be queried with the second element in the target file in the IP address library to determine the encoding result of the home location corresponding to the IP to be queried; The coding result of the place of origin corresponding to the IP to be queried is associated with the place of origin coding table in the IP address library to obtain the place of origin corresponding to the IP to be queried.
7. An IP address library construction device, characterized in that: include: An acquisition module is used to acquire an Internet Protocol IP list; the IP list contains multiple IPs; A construction module is used to construct an IP address library according to the multiple IPs in the IP list; the IP address library includes a target file and a location code table; wherein, The target file includes a first element and a plurality of second elements; the first element is used to indicate the number of second elements in the IP address library; the second element is used to store the encoding result of the target IP and the location corresponding to the target IP; the data types of the target IP and the encoding result are integer int; The attribution coding table includes the corresponding relationship between the attribution and the coding result; The step of constructing an IP address library according to the plurality of IPs in the IP list comprises: Arrange multiple IPs in the IP list in ascending order to obtain a target IP list; the target IP list is the IP list in ascending order; In the case where the location corresponding to the second IP in the target IP list is the same as the location corresponding to the first IP, the encoding result of the second IP and the location corresponding to the second IP is abandoned to be stored in the target file in the IP address library; the first IP and the second IP are two adjacent IPs in the target IP list; the value of the first IP is less than the value of the second IP; When the place of attribution corresponding to the second IP in the target IP list is different from the place of attribution corresponding to the first IP, the encoding result of the first IP and the place of attribution corresponding to the first IP are stored in the target file in the IP address library, and the value of the first element in the target file is increased by 1.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method for constructing an IP address library as described in any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for constructing an IP address library as described in any one of claims 1 to 6 are implemented.
