CN114357274A - IP information query method and device - Google Patents

IP information query method and device Download PDF

Info

Publication number
CN114357274A
CN114357274A CN202111621861.8A CN202111621861A CN114357274A CN 114357274 A CN114357274 A CN 114357274A CN 202111621861 A CN202111621861 A CN 202111621861A CN 114357274 A CN114357274 A CN 114357274A
Authority
CN
China
Prior art keywords
address
record
character string
segment
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111621861.8A
Other languages
Chinese (zh)
Inventor
丁桥
冯嵩
江枕岳
周伟
张届新
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Telecom Corp Ltd
Original Assignee
China Telecom Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Telecom Corp Ltd filed Critical China Telecom Corp Ltd
Priority to CN202111621861.8A priority Critical patent/CN114357274A/en
Publication of CN114357274A publication Critical patent/CN114357274A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the invention provides an IP information query method and device, the method comprises the steps of determining a corresponding IP address from a detected IP information query request, carrying out bit-by-bit segmentation processing on the IP address according to a set mask bit, determining a first IP character string, determining whether the first IP character string exists in a first cascade type IP record, and matching the IP address with each IP address in a second cascade type IP record when determining that the IP information associated with the first IP character string does not exist in the first cascade type IP record if the first IP character string exists in the first cascade type IP record, so as to determine the IP information corresponding to the IP address. Therefore, the scheme can effectively save the time consumed by conversion operation aiming at the IP address by segmenting the IP address according to the mask bit, and only carries out the second-stage query aiming at the IP address which does not store the IP information in the first-stage IP record, thereby effectively improving the query efficiency of the IP information.

Description

IP information query method and device
Technical Field
The embodiment of the invention relates to the technical field of network and information security, in particular to an IP information query method and device.
Background
With the development of computer technology, in some big data processing, IP address query is needed, and generally, in order to query relevant information corresponding to an IP, query is needed according to an IP database.
At present, there are two general IP information query methods, that is, the first IP information query method is: the IP addresses are stored in a database in advance in the form of address segments (such as Redis or mysql), and meanwhile, the start IP and the end IP of each IP address segment in the database need to be converted into long integers in advance for storage, so as to facilitate subsequent matching query for the IP addresses. When the relevant information corresponding to a certain IP address needs to be queried, the IP address needs to be converted into a long integer, and then the converted IP address and each converted IP address segment are subjected to matching query, so that the relevant information corresponding to the IP address needing to be queried is queried. However, in this IP address query method, the query needs to be performed after the conversion of the IP address, and therefore, it takes a long time to query the IP information, which results in low efficiency of querying the IP information. The second IP information query method is: the method includes the steps that all IP addresses are directly stored in a database (such as Redis or mysql) in advance, when related information corresponding to a certain IP address needs to be inquired, the IP address is directly compared with all the IP addresses in the database, and therefore the related information corresponding to the IP address needing to be inquired is inquired. However, when the IP address query method is applied to IP queries of a large scale, the IP information query efficiency is low, the requirement for the cache capacity is high, and the hardware resource investment is large because the IP address query method needs to compare with each IP address in the database.
In summary, there is a need for an IP information query method to effectively improve the query efficiency of IP information.
Disclosure of Invention
The embodiment of the invention provides an IP information query method and device, which are used for effectively improving the query efficiency of IP information.
In a first aspect, an embodiment of the present invention provides an IP information query method, including:
when an IP information query request aiming at any network protocol IP address is detected, determining a corresponding IP address from the IP information query request;
according to a set mask bit, carrying out bit-by-bit segmentation processing on the IP address to determine a first IP character string;
determining whether the first cascade IP character string exists in a first cascade IP record;
if yes, matching the IP address with each IP address in the second cascade type IP record when the first cascade type IP record is determined to have no IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
In the above technical solution, when the IP information corresponding to the IP address is queried in the prior art, the IP address needs to be converted for matching or directly matched, but all the solutions consume a certain time to match the IP address, thereby resulting in low efficiency of querying the IP information. Aiming at the problem, the technical scheme of the invention is to divide the IP address according to the mask bit instead of adding different weights after converting the IP address, so that the time overhead can be effectively reduced, the hierarchical query in the second-level-connection-type IP record can be further carried out only on the IP address without the associated IP information in the first-level-connection-type IP record, and the corresponding IP information can be timely and accurately queried only in the first-level-connection-type IP record aiming at the IP address with the associated IP information in the first-level-connection-type IP record, so that the storage overhead of the IP address can be effectively reduced, and the query efficiency of the IP information can be effectively improved. Specifically, when an IP information query request for any IP address is detected, the corresponding IP address can be analyzed from the IP information query request, and according to the set mask bits, bit-by-bit segmentation processing can be performed on the IP address to obtain the first IP character string, so that time consumed by adding different weights after converting the IP address can be saved. Determining whether the first IP character string exists in the first cascaded IP record, which is equivalent to performing first-stage matching on the IP address, if it is determined that the first IP character string exists in the first cascaded IP record but no IP information associated with the first IP character string exists, matching the IP address corresponding to the first IP character string with each IP address in the second cascaded IP record, and determining the IP information corresponding to the IP address when the matching is successful, that is, performing second-stage query on the IP address corresponding to the first IP character string only under the precondition that a certain first IP character string is stored in the first cascaded IP record but no IP information associated with the first IP character string is stored, so that query time for the IP address corresponding to the IP information associated with the first IP character string and a certain first IP character string is stored in the first cascaded IP record can be reduced (because the first cascaded IP record stores a certain first IP character string and stores IP address corresponding to the IP information associated with the first IP character string) The IP record stores a certain first IP character string and stores the IP address corresponding to the IP information associated with the first IP character string, only the first-level query is carried out), and the expense for storing a large number of single IP addresses can be effectively reduced. Therefore, the scheme can effectively save the time consumed by taking different weights for addition after the IP address is converted by segmenting according to the mask bit, and only carries out the second-stage query on the IP address corresponding to the IP information which is not stored with the first IP character string but stored with a certain first IP character string in the first cascade type IP record, thereby effectively improving the query efficiency of the IP information.
Optionally, the method further comprises:
and when determining that the IP information associated with the first IP character string exists in the first cascade type IP record, determining the IP information as the IP information corresponding to the IP address.
In the above technical solution, when it is determined that the first cascade IP record stores the first IP string and stores the IP information associated with the first IP string, the IP information corresponding to the first IP string can be directly queried from the first cascade IP record, and the IP information is the IP information of the IP address corresponding to the first IP string, and there is no need to perform a second-stage query on the IP address, so that the number of queries on the IP address can be effectively reduced, and the query efficiency of the IP information can be effectively improved.
Optionally, the first cascaded IP record is used to indicate that a first level query is performed for an IP address; the second cascade IP record is used for indicating second-stage query aiming at the IP address; the second level query belongs to a hierarchical query of the first level query.
In the above technical solution, each IP address is divided into two types of IP addresses according to the attribute of each IP address (label attribute carried by each IP address after IP address allocation is performed according to different regions, such as countries or cities, or according to different enterprises, etc.), that is, an IP address having the attribute of the whole IP segment and an IP address not having the attribute of the whole IP segment. Because at least one IP address having the entire IP attribute generally belongs to the same region or the same enterprise, and the like, that is, based on the characteristic that a certain segment (for example, segment C) in the IP addresses is relatively concentrated, the second character string corresponding to the at least one IP address having the entire IP attribute and the corresponding IP information are stored in the first-level IP record, and the IP addresses having no entire IP segment attribute (that is, a small portion of scattered IPs are not located in the entire IP segment) and the corresponding IP information are stored in the second-level IP record, so that the subsequent queries located in the entire IP segment (IP start address-IP end address) can be effectively reduced. The first cascade type IP record is used for carrying out first-stage query on an IP address; the second-level IP record is used for performing second-level query on an IP address, that is, the second-level query is performed on the IP address that needs to be queried in a hierarchical manner, for example, a first IP character string corresponding to a certain IP address exists in the first-level IP record, but the first-level IP record does not have IP information associated with the first IP character string, so that when the first-level IP record needs to be queried, the second-level query is performed on the IP address in the second-level IP record, that is, the second-level query is equivalent to performing hierarchical query on the IP address, so that it is possible to query the IP information corresponding to the IP address.
Optionally, the performing bit-by-bit splitting processing on the IP address according to the set mask bit to determine a first IP character string includes:
performing bit-wise segmentation processing on the IP address in a preset direction according to the set mask bit to obtain the first IP character string which accords with the set mask bit; wherein, the preset direction is from left to right or from right to left.
In the above technical solution, after the set mask bit is determined, the set mask bit is used as a segmentation reference, and the bit segmentation is performed on the IP address according to a preset direction (for example, from left to right or from right to left), so that the first IP character string conforming to the set mask bit can be accurately obtained.
Optionally, the performing bit-by-bit segmentation processing on the IP address in a preset direction to obtain the first IP string meeting the set mask bit includes:
if the set mask bit is 24, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address; or, performing bitwise cutting processing on the segment D of the IP address in the sequence from right to left to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address;
if the set mask bit is 16, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A and the segment B of the IP address; or, performing bitwise cutting processing on the segment C and the segment D of the IP address in the order from right to left to obtain the first IP character string consisting of the segment A and the segment B of the IP address.
In the above technical solution, based on the characteristics of the IP address (that is, the IP address is composed of a segment a, a segment B, a segment C, and a segment D, each segment is converted into a binary system and occupies 8 bits, that is, 8 bits), and according to the behavior of using the IP address in each business or each area at present, it can be known that there are two types of mask bits which are usually set, one is 24 and the other is 16, that is, when the set mask bit is 24, the IP address is bit-sliced in the order from left to right, or the segment D of the IP address is bit-sliced in the order from right to left, so that the first IP character string composed of the segment a, the segment B, and the segment C can be accurately obtained. And when the set mask bit is 16, carrying out bit segmentation processing on the IP address in the order from left to right, or carrying out bit cutting processing on the C section and the D section of the IP address in the order from right to left, so as to accurately obtain the first IP character string consisting of the A section and the B section. Therefore, the scheme is convenient for quickly inquiring the IP information corresponding to the IP address subsequently through the first IP character string.
Optionally, the first cascaded IP record and the second cascaded IP record are determined by:
acquiring each IP address with the attribute of the whole IP section, each IP information corresponding to each IP address with the attribute of the whole IP section, each IP address without the attribute of the whole IP section and each IP information corresponding to each IP address without the attribute of the whole IP section from an IP home database;
according to set mask bits, performing bit-by-bit segmentation processing on the IP addresses with the integral IP section attribute and the IP addresses without the integral IP section attribute respectively to obtain second IP character strings corresponding to the IP addresses with the integral IP section attribute and second IP character strings corresponding to the IP addresses without the integral IP section attribute;
storing the second IP character strings corresponding to the IP addresses with the integral IP section attribute, the IP information corresponding to the IP addresses with the integral IP section attribute and the second IP character strings corresponding to the IP addresses without the integral IP section attribute in the first-level IP record, and storing the IP addresses without the integral IP section attribute and the IP information corresponding to the IP addresses without the integral IP section attribute in the second-level IP record.
In the above technical solution, through the IP home base, which IP addresses in the IP home base belong to an entire IP segment and which IP addresses belong to a non-entire IP segment (i.e., scattered IPs) can be determined, so when dividing each IP address into two levels of IP records (i.e., a first-level IP record and a second-level IP record), first, a mask bit needs to be determined, for example, a mask bit (e.g., 24) is determined according to the current areas (e.g., according to city levels) and the use cases of each industry for the IP addresses, that is, based on the characteristic of relative concentration of a certain segment (e.g., a C segment) of the IP address, for example, a certain city is allocated with a certain entire IP segment (e.g., a whole C segment), the whole IP segment includes a plurality of IP addresses, or a certain city is allocated with a certain non-entire IP segment, for example, one or more zero-scattered IP addresses. Based on the characteristic that a certain segment (such as a segment C) of an IP address is relatively concentrated, when a certain IP address belonging to the segment C is queried, corresponding IP information can be quickly obtained through an IP character string formed by the segment a, the segment B and the segment C of the IP address (since the segment a, the segment B and the segment C already represent the attribute of the IP address and do not need to match the segment D, the whole IP address does not need to be taken for matching, and for the IP address having the attribute of the whole IP segment, matching can be quickly and accurately completed only by a part of information in the IP address), and for the query efficiency of subsequent IP addresses, bitwise splitting processing can be performed on each IP address having the attribute of the whole IP segment and each IP address not having the attribute of the whole IP segment according to a set mask bit. Meanwhile, for the IP address with the attribute of the whole IP section, the corresponding IP information can be inquired through the first-stage inquiry without the second-stage hierarchical inquiry, but for the IP address without the attribute of the whole IP section, whether the corresponding IP information can be inquired can be determined through the second-stage hierarchical inquiry, so that the first-stage linked IP record can store the corresponding IP information only for the IP address with the attribute of the whole IP section (because the IP address with the attribute of the whole IP section does not need to be matched with the D section of the IP address, the matching can be quickly and accurately completed only by the A section, the B section and the C section of the IP address), thereby effectively reducing the inquiry times for the IP address with the attribute of the whole IP section; the second-level IP record only stores the corresponding IP information for the IP address without the attribute of the whole IP segment (because the IP address without the attribute of the whole IP segment needs to match the segment D of the IP address, a second-level query for the segment D, that is, a hierarchical query for the segment D, is set to query the IP information corresponding to the IP address without the attribute of the whole IP segment). Therefore, according to the scheme, the IP information query performance can be effectively improved by constructing two levels of IP records (namely the first level-connected IP record and the second level-connected IP record) for querying the IP information of the IP addresses with different IP attributes (such as the integral IP section attribute and the non-integral IP section attribute).
Optionally, determining whether the first IP string exists in the first cascaded IP record includes:
and sequentially matching the first IP character string with each second IP character string in the first cascade type IP record in a preset matching mode, so as to determine whether the first IP character string exists in the first cascade type IP record.
In the above technical solution, when a first-level query is performed on a certain IP address through a first cascade IP record, that is, a first IP character string corresponding to the IP address is sequentially matched with each second IP character string in the first cascade IP record, and when it is determined that the first IP character string is successfully matched with a certain second IP character string, IP information associated with the second IP character string may be determined as IP information corresponding to the IP address.
In a second aspect, an embodiment of the present invention further provides an IP information query apparatus, including:
the device comprises a detection unit, a processing unit and a processing unit, wherein the detection unit is used for determining a corresponding IP address from an IP information query request when the IP information query request aiming at any network protocol IP address is detected;
the processing unit is used for carrying out bit-by-bit segmentation processing on the IP address according to a set mask bit to determine a first IP character string; determining whether the first cascade IP character string exists in a first cascade IP record; if yes, matching the IP address with each IP address in the second cascade type IP record when the first cascade type IP record is determined to have no IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
Optionally, the processing unit is further configured to:
and when determining that the IP information associated with the first IP character string exists in the first cascade type IP record, determining the IP information as the IP information corresponding to the IP address.
Optionally, the first cascaded IP record is used to indicate that a first level query is performed for an IP address; the second cascade IP record is used for indicating second-stage query aiming at the IP address; the second level query belongs to a hierarchical query of the first level query.
Optionally, the processing unit is specifically configured to:
performing bit-wise segmentation processing on the IP address in a preset direction according to the set mask bit to obtain the first IP character string which accords with the set mask bit; wherein, the preset direction is from left to right or from right to left.
Optionally, the processing unit is specifically configured to:
if the set mask bit is 24, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address; or, performing bitwise cutting processing on the segment D of the IP address in the sequence from right to left to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address;
if the set mask bit is 16, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A and the segment B of the IP address; or, performing bitwise cutting processing on the segment C and the segment D of the IP address in the order from right to left to obtain the first IP character string consisting of the segment A and the segment B of the IP address.
Optionally, the processing unit is specifically configured to:
acquiring each IP address with the attribute of the whole IP section, each IP information corresponding to each IP address with the attribute of the whole IP section, each IP address without the attribute of the whole IP section and each IP information corresponding to each IP address without the attribute of the whole IP section from an IP home database;
according to set mask bits, performing bit-by-bit segmentation processing on the IP addresses with the integral IP section attribute and the IP addresses without the integral IP section attribute respectively to obtain second IP character strings corresponding to the IP addresses with the integral IP section attribute and second IP character strings corresponding to the IP addresses without the integral IP section attribute;
storing the second IP character strings corresponding to the IP addresses with the integral IP section attribute, the IP information corresponding to the IP addresses with the integral IP section attribute and the second IP character strings corresponding to the IP addresses without the integral IP section attribute in the first-level IP record, and storing the IP addresses without the integral IP section attribute and the IP information corresponding to the IP addresses without the integral IP section attribute in the second-level IP record.
Optionally, the processing unit is specifically configured to:
and sequentially matching the first IP character string with each second IP character string in the first cascade type IP record in a preset matching mode, so as to determine whether the first IP character string exists in the first cascade type IP record.
In a third aspect, an embodiment of the present invention provides a computing device, including at least one processor and at least one memory, where the memory stores a computer program, and when the program is executed by the processor, the processor is caused to execute the IP information querying method according to any of the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the program causes the computing device to execute the IP information querying method according to any one of the first aspect.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of an IP information query method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a C-domain dictionary table and a D-domain dictionary table constructed based on a static IP address list according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an IP information query apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computing device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 exemplarily shows a flow of an IP information query method provided by an embodiment of the present invention, where the flow may be executed by an IP information query device.
As shown in fig. 1, the process specifically includes:
step 101, when an IP information query request for any network protocol IP address is detected, determining a corresponding IP address from the IP information query request.
In some big data processing, the embodiment of the present invention may need to use IP address query to query the relevant IP information of the IP address. Based on this, if a user wants to query IP information related to a certain IP address, an IP information query request including the IP address needs to be generated by a client in a terminal device (such as a laptop, a desktop, a smart phone, or other network devices). Or, an IP information query instruction is generated by editing on a client in the used terminal equipment, and the IP information query instruction comprises an IP address. The IP information query method is executed by an IP information query device, which may be a network device (such as a computer) or a communication device capable of supporting the network device to implement the functions required by the method, such as a system on a chip. The network equipment receives the IP information inquiry requests or the IP information inquiry instructions sent by the users, and sends the IP information inquiry requests or the IP information inquiry instructions to the network equipment in a parallel mode. A user may also simultaneously generate a plurality of IP information query requests or a plurality of IP information query instructions in batch, and send the plurality of IP information query requests or the plurality of IP information query instructions to the network device. Illustratively, taking an IP information query request or an IP information query instruction as an example, an IP information query request or an IP information query instruction generated by a certain user is sent to the network device, and after detecting the IP information query request or the IP information query instruction sent by the user, the network device may perform parsing processing on the IP information query request or the IP information query instruction, so as to parse a corresponding IP address.
And 102, carrying out bit-by-bit segmentation processing on the IP address according to a set mask bit, and determining a first IP character string.
In the embodiment of the invention, after the network equipment analyzes the IP address contained in a certain IP information query request, the network equipment can perform bit-by-bit segmentation processing on the IP address according to the set mask bit, thereby determining the first IP character string. The mask bits set are set in advance based on the requirements of the actual application scenario (i.e. the mask bits that may be needed by different application scenarios are different). That is, each IP character string stored in the first cascade IP record is generated by splitting each IP address according to a set mask bit, which is convenient to improve the query efficiency of the IP address, so after the IP address is resolved, the first IP character string corresponding to the set mask bit can be accurately obtained by performing bit-wise splitting processing on the IP based on a preset direction according to the set mask bit, that is, the set mask bit is used as a splitting reference. Wherein, the preset direction is from left to right or from right to left.
When the IP address is split in bits in a preset direction, based on the characteristics of the IP address (i.e., the IP address is composed of a segment a, a segment B, a segment C, and a segment D, each segment occupies 8 bits by binary conversion), and the behavior of using the IP address according to each business or each area (such as a city level) in the current line, that is, based on the characteristic that a certain segment (such as the segment C) of the IP address is relatively concentrated, for example, a certain whole IP segment (such as the whole segment C) is allocated to a certain city, and the whole IP segment contains a plurality of IP addresses, or a certain non-whole IP segment is allocated to a certain city, for example, a certain or several zero-dispersion IP addresses, it can be known that there are two types of mask bits, one type is 24, and the other type is 16. That is, if the set mask bit is 24, the first IP character string composed of the a segment, the B segment, and the C segment can be accurately obtained by performing the bitwise division processing on the IP address in the order from left to right, or performing the bitwise cutting processing on the D segment of the IP address in the order from right to left. If the set mask bit is 16, the IP address is subjected to bitwise segmentation processing from left to right, or the C section and the D section of the IP address are subjected to bitwise cutting processing from right to left, so that the first IP character string consisting of the A section and the B section of the IP address can be accurately obtained. Therefore, the scheme is convenient for quickly inquiring the IP information corresponding to the IP address subsequently through the first IP character string.
For example, taking the mask bit as 24 and the preset direction as from left to right as an example, when an IP address included in an IP information query request generated by a user is a.b.c.d, a segmentation is performed according to the mask/24 position, that is, in order from left to right, a bitwise segmentation is performed on the IP address until c stops, because c just satisfies 24 bits, so that an IP string "a.b.c" can be extracted from the IP address, and by sequentially matching the IP string with each second IP string in the first-level IP record, if the matching is not successful, the IP address corresponding to the IP string is discarded, and if the matching is successful, it is determined whether the IP string belongs to the whole IP segment or the non-whole IP segment, and since the IP string belonging to the whole IP segment in the first-level IP record is stored in the form of key value pairs (that is an IP string as a key, and if the IP character string belongs to the non-integral IP section, the corresponding IP information can be directly obtained from the first-level IP record without performing second-level query in the second-level IP record, and if the IP character string belongs to the non-integral IP section, the corresponding IP information can not be obtained from the first-level IP record and the second-level query needs to be performed in the second-level IP record. Or, for example, when the IP address included in a certain IP information query request generated by a certain user is 45.115.45.3, the IP address is split once according to the position where the mask is/24, that is, the IP address is split bit by bit in the order from left to right, and the splitting to 5 before 3 stops, because the 5 before 3 meets just 24 bits, so that the IP string "45.115.45" can be extracted from the IP address.
And 103, determining whether the first cascade IP character string exists in the first cascade IP record.
In the embodiment of the invention, before judging whether the first cascade type IP character string exists in the first cascade type IP record, the first cascade type IP record and the second cascade type IP record need to be determined in advance. It should be noted that, by using the attributes of each IP address (the label attributes carried by each IP address after IP addresses are allocated according to different regions, such as countries or cities, or according to different enterprises), each IP address can be divided into two types of IP addresses, that is, an IP address having the attribute of the whole IP segment and an IP address not having the attribute of the whole IP segment. Because at least one IP address having the integral IP attribute usually belongs to the same region or the same enterprise, and the like, that is, based on the characteristic that a certain segment (for example, segment C) in the IP address is relatively concentrated, the second character string corresponding to the at least one IP address having the integral IP attribute and corresponding respective IP information are stored in the first-level IP record in the form of a key-value pair, and the IP addresses having no integral IP segment attribute (that is, a small portion of scattered IPs are not located in the integral IP segment) and corresponding respective IP information are stored in the second-level IP record in the form of a key-value pair, so that subsequent queries located in the integral IP segment (IP start address-IP end address) can be effectively reduced. The first cascade type IP record is used for indicating that first-stage query is carried out on an IP address; the second-level connection type IP record is used for indicating second-level query aiming at the IP address; the second level query belongs to a hierarchical query of the first level query. For example, a first IP string corresponding to a certain IP address exists in the first cascaded IP record, but the first cascaded IP record does not have IP information associated with the first IP string, so that in order to query the IP information associated with the first IP string, a second-level query needs to be performed on the IP address in the second cascaded IP record, that is, a hierarchical query is performed on the IP address, so that it is possible to query the IP information corresponding to the IP address.
Specifically, when determining the first-level IP record and the second-level IP record, the IP home library may determine which IP addresses in the IP home library belong to the whole IP segment and which IP addresses belong to the non-whole IP segment (i.e., scattered IPs), that is, the IP home library may obtain each IP address having the whole IP segment attribute, each IP information corresponding to each IP address having the whole IP segment attribute, each IP address not having the whole IP segment attribute, and each IP information corresponding to each IP address not having the whole IP segment attribute. In this case, it is also necessary to perform bitwise splitting processing on each IP address having the whole IP segment attribute and each IP address not having the whole IP segment attribute in a preset direction (for example, from left to right or from right to left) according to the set mask bit, so that each second IP character string corresponding to each IP address having the whole IP segment attribute and each second IP character string corresponding to each IP address not having the whole IP segment attribute can be accurately obtained. Thus, compared with the first existing IP information query mode, the scheme does not need IP conversion operation (for example, the first existing IP information query mode adopts a classic red and black tree algorithm, the specific search method is that if the key to be searched is equal to the key of the root node, the search is hit, otherwise, the search is continued in a proper sub-tree, if the key to be searched is smaller, the left sub-tree is selected, and if the fruit tree is empty, the search is not hit, along with the continuous downward search, the size of the sub-tree represented by the current node is reduced, meanwhile, the starting address and the ending address of the IP section are converted into long integers, then different weights are taken to be added, and then the construction of the red and black tree is carried out, when the IP sections are too many, the red and black tree becomes too large, the depth of the tree becomes large, thereby the query efficiency is reduced), the time overhead can be effectively reduced, thereby, the query efficiency for the IP address can be improved. Then, according to the functions of the first cascade type IP record and the second cascade type IP record, storing each second IP character string corresponding to each IP address with the integral IP section attribute and each IP information corresponding to each IP address with the integral IP section attribute into the first cascade type IP record in a key value pair mode, and storing each second IP character string corresponding to each IP address without the integral IP section attribute into the first cascade type IP record; and storing each IP address without the integral IP section attribute and each IP information corresponding to each IP address without the integral IP section attribute into a second-level-connected IP record in a key value pair mode. Thus, for the IP address with the whole IP segment attribute, the corresponding IP information can be queried only by performing the first-level query in the first-level IP record, and the second-level query in the second-level IP record is not needed. For example, for a certain region, the region is assigned with a plurality of IP addresses having an attribute of a whole segment C, and each second IP string composed of a segment a, a segment B, and a segment C is also stored in the first cascade IP record, so that since the segment a, the segment B, and the segment C already represent the attribute of the IP address, matching of the segment D is not required, and thus, the whole IP address does not need to be taken for matching, and for an IP address having an attribute of a whole segment C, matching can be completed quickly and accurately only by a part of information in the IP address, so that the number of times of querying for an IP address having an attribute of a whole IP segment can be effectively reduced. For an IP address without the attribute of the whole IP segment, the associated IP information is not queried in the first cascaded IP record, and a second-stage query is required in the second cascaded IP record, that is, the IP address without the attribute of the whole IP segment needs to match the segment D of the IP address in the second cascaded IP record (that is, the whole IP address is taken out to be matched in the second cascaded IP record) in addition to matching the IP character string composed of the segment a, the segment B, and the segment C in the first cascaded IP record, so as to query the IP information corresponding to the IP address without the attribute of the whole IP segment.
Illustratively, according to the characteristic that a static IP address list (i.e. an IP address home base) is relatively concentrated in a certain mask segment (such as a C segment of an IP address), the mask with a large-scale whole IP segment is used for division, and cascaded IP domains are constructed to reduce queries in the whole segment of IP. In order to fully exert the rapid searching performance of a database (such as Redis), the transverse key value of the comparison database can be expanded to 1000 ten thousand levels, and the number of longitudinally cascaded Redis databases is controlled to be 2-3. For example, in order to identify a scene threatening an IP in an information security pneumatic control work, a fast query of a home location for the IP in DNS (Domain Name System) recursive resolution data is required. The total number of IPv4(Internet Protocol Version 4, fourth edition) addresses is over 42 hundred million globally, and the addresses are expressed in decimal in the database as: 0.0.0.0-255.255.255.255. The IP home base stores the information of the country and city to which the IP belongs according to regions, wherein IP sections are generally divided into cities by using at least 1C (A.B.C.0-A.B.C.255 contain 256/32 IPs) as a basic unit, and the small number of addresses are divided into less than 1C. However, it is not desirable to store all IP segments as scattered IPs exclusively for these small portions of network addresses. Therefore, according to the technical scheme of the invention, the IP information query performance can be effectively improved by constructing two-level IP records (namely the first level-connected IP record and the second level-connected IP record) for querying the IP information of the IP addresses with different IP attributes (such as the attribute of the whole IP section and the attribute of the non-whole IP section) and caching through Redis.
Specifically, a two-level table (i.e. a first-level connected IP record and a second-level connected IP record) of a C domain (i.e. a segment, and a segment of an IP address) and a D domain (i.e. a segment, and a segment of an IP address, i.e. a complete IP address) is constructed in a certain database (e.g. Redis), wherein the C domain dictionary table includes a complete IP segment and a non-complete IP segment, so that most of the IP addresses only need to search for/24C segments, and a small part of scattered IP addresses are not in the complete IP segment, which needs to search for D segments, thereby greatly improving the efficiency of searching for IP information, and reducing the overhead consumed by searching for IP information, such as constructing a C domain dictionary table first, i.e. a C segment prefix character string with mask of/24C segment, for the IP address of the complete IP segment, storing corresponding IP information (e.g. attribute values of the IP address in the C domain dictionary table, for example, which area or which city the IP address belongs to), for the IP address of the scattered non-integral IP segment, only the C segment prefix character string with the mask of/24 of the IP address is stored in the C domain dictionary table, and the corresponding IP information is not stored, but of course, a D domain dictionary table is provided for the IP address of the scattered non-integral IP segment, and is used for storing the a segment, the B segment, the C segment, and the D segment of the IP address, that is, the IP character string with the mask of/32, and the corresponding IP information.
For example, taking a large-scale static IP library as shown in table 1 as an example, an implementation process for constructing a C domain dictionary table and a D domain dictionary table is described.
TABLE 1
IP address range of values IP information
45.115.44.0~45.115.46.255 Continental region 001
46.103.2.0~46.103.2.255 Continental region 002
47.132.44.2~47.132.44.255 Continental region 009
It can be seen from table 1 that there are multiple whole IP segments, such as 45.115.44-45.115.45, 45.115.45-45.115.46, etc., where a few regions have scattered IP addresses, such as the IP address corresponding to the continental region 009. In addition, it should be noted that, since the C segments in the IP address corresponding to the continental region 001 are relatively concentrated, that is, 45.115.44-45.115.45, 45.115.45-45.115.46 are all associated with the continental region 001, it can be seen that the a segment, the B segment, and the C segment in the IP address already represent the attribute of the IP address (i.e., the attribute corresponding to the continental region 001), so that the IP information corresponding to the IP address (i.e., the continental region 001) can be determined only by matching the IP character string composed of the a segment, the B segment, and the C segment, and there is no need to match the D segment. For example, the IP address corresponding to the continental region 009 does not have a whole IP segment, and belongs to scattered IP addresses, and further query is required, that is, query in the D domain is required to query the corresponding IP information.
For each IP address in table 1, the IP character string corresponding to each IP address can be obtained by performing bit splitting processing on each IP address according to a set mask bit (for example, 24), for example, the IP character string "45.115.44" corresponding to each IP address can be obtained by performing bit splitting processing on the IP address 45.115.44.0 in table 1 in order from left to right according to the splitting reference of the mask bit 24, or the IP character string "46.103.2" corresponding to each IP address can be obtained by performing bit splitting processing on the IP address 46.103.2.0 in table 1 in order from left to right according to the splitting reference of the mask bit 24. And for the scattered IP addresses of the non-integral IP section, a D domain needs to be constructed, namely, a mapping relation between the IP integral address and the IP information is created. In this way, a C domain dictionary table and a D domain dictionary table for IP addresses can be constructed as shown in table 2.
TABLE 2
Figure BDA0003438337850000161
Figure BDA0003438337850000171
When determining whether the first cascade type IP record has the first IP character string, sequentially matching the first IP character string with each second IP character string in the first cascade type IP record through a preset matching mode (such as cosine similarity calculation, Pearson correlation coefficient algorithm or other character matching rules, and the like) so as to determine whether the first IP character string exists in the first cascade type IP record. If a certain second IP character string is successfully matched with the first IP character string in the first cascade type IP record, determining that the first IP character string exists in the first cascade type IP record; if the first cascade type IP record does not have any second IP character string successfully matched with the first IP character string, the first cascade type IP record can be determined not to have the first IP character string, so that the IP address can be discarded without subsequent matching processes. Exemplarily, taking a cosine similarity algorithm as an example, determining each similarity value of the first IP character string and each second IP character string in the first cascaded IP record by the cosine similarity algorithm, comparing the similarity values to determine a maximum similarity value, and if the maximum similarity value is greater than or equal to a preset threshold, determining that the second IP character string corresponding to the maximum similarity value is successfully matched with the first IP character string. For example, taking the IP address as 45.115.44.0, the IP address is bit-sliced according to a set mask bit (e.g., 24) to obtain a first IP string "45.115.44". Determining similarity values of the first IP character string '45.115.44' and second IP character strings in the first cascade IP record by a cosine similarity algorithm, comparing the similarity values to determine a maximum similarity value (such as 0.85), and if the maximum similarity value 0.85 is greater than a preset threshold (such as 0.8), determining that the second IP character string '45.115.44' corresponding to the maximum similarity value is successfully matched with the first IP character string '45.115.44'. Or, a direct character matching mode is adopted, that is, the first IP character string is sequentially subjected to character matching with each second IP character string in the first cascade IP record, that is, each character in the first character string is compared with each character of any second IP character string in sequence, and if one second IP character string is successfully subjected to character matching with the first IP character string, it is determined that the first IP character string exists in the first cascade IP record.
Or, taking a C domain dictionary table and a D domain dictionary table constructed by another static IP address list as shown in fig. 2 as an example, taking an IP address value range (e.g., 172.10.1.0-172.10.9.255) corresponding to a certain city as an example, the IP address value range corresponding to the city has a plurality of whole IP segments, which indicates that the IP address corresponding to the city has the whole IP segment attribute. Illustratively, taking an IP address in the city as an example, for example, 172.10.1.0 as an example, according to the splitting reference of mask bits 24, performing bitwise splitting on the IP address in order from left to right to obtain an IP string "172.10.1", matching the IP string with each IP string in a C-domain dictionary table (i.e. a first-level connected IP record), if there is an IP string in the C-domain dictionary table and the IP string is successfully matched, determining that the IP string exists in the C-domain dictionary table, and determining whether the IP string has an entire IP segment attribute, or determining whether IP information associated with the first IP string exists in the C-domain dictionary table, if so, directly obtaining the IP string from the C-domain dictionary table, that is, the IP information corresponding to "172.10.1" (e.g. a value of 1), and thus obtaining a value of "1", and thus completing matching on the IP address, if any IP character string does not exist in the C-domain dictionary table and the IP character string is successfully matched, the matching of the IP character string is failed, and the IP address corresponding to the IP character string can be discarded. Or taking an IP address value range (for example, 172.10.10.1-172.10.10.127) corresponding to another city as an example, the IP address value range corresponding to the city does not have a whole IP segment, which indicates that the IP address corresponding to the city does not have a whole IP segment attribute. Illustratively, taking an IP address in the city as an example, for example, 172.10.10.1, bit-wise splitting is performed on the IP address in order from left to right according to the splitting reference of the mask bit 24, so as to obtain an IP character string "172.10.10", matching the IP character string with each IP character string in the C-domain dictionary table, if there is an IP character string successfully matched with the IP character string in the C-domain dictionary table, determining that the IP character string exists in the C-domain dictionary table, and determining whether the IP character string has an integral IP segment attribute, or determining whether there is IP information associated with the first IP character string in the C-domain dictionary table, if not, it is known that the IP character string belongs to a non-integral IP segment, and it is required to perform a second-level matching on the IP address "172.10.10.1" with each IP address in the D-domain dictionary table, if there is an address successfully matched with the IP address in the D-domain dictionary table, the IP information (for example, the value a) corresponding to the IP address 172.10.10.1, that is, the value "a" is obtained, so that for the matching of the IP address is completed, if there is no IP address in the D-domain dictionary table that matches the IP address successfully, the matching of the IP address fails, and there is no IP information associated with the IP address.
And 104, if the first IP character string exists in the first cascade type IP record, matching the IP address with each IP address in a second cascade type IP record when the first cascade type IP record does not contain IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
In the embodiment of the invention, after a first IP character string is determined to exist in a first cascade type IP record, whether the first IP character string has the attribute of a whole IP section can be determined, namely, whether the first IP character string belongs to the whole IP section or a non-whole IP section is determined, if the first IP character string is determined to have the attribute of the whole IP section, corresponding IP information can be directly obtained from the first cascade type IP record without performing second-stage query in a second cascade type IP record to obtain the corresponding IP information, namely, when the IP information associated with the first IP character string exists in the first cascade type IP record, the IP information can be determined as the IP information corresponding to an IP address, so that the query times aiming at the IP address can be effectively reduced, and the query efficiency of the IP information is effectively improved; if the first IP character string is determined not to have the attribute of the whole IP section, the corresponding IP information can not be obtained in the first cascade type IP record, at the moment, the second-stage query needs to be carried out in the second cascade type IP record aiming at the IP address without the attribute of the whole IP section so as to query the corresponding IP information, and thus, the proposal does not need to compare the interval aiming at the IP address, and can save the expenses of calculating and comparing the interval edge, thereby improving the matching efficiency aiming at the IP address, and in addition, the scheme can greatly save the investment of hardware resources (mainly memory) (for example, if the IP table is expanded to 3 hundred million or 32 hundred million in size, the existing second IP information query mode can be realized only by investing several times of hardware resources to achieve the same query capability), and meanwhile, the query times of IP addresses in the whole IP section can be reduced. Or, it may be determined whether the first cascaded IP record includes the IP information associated with the first IP string, and if it is determined that the first cascaded IP record includes the IP information associated with the first IP string, the corresponding IP information may be directly acquired from the first cascaded IP record without performing a second-level query in the second cascaded IP record to acquire the corresponding IP information. If it is determined that the IP information associated with the first IP string does not exist in the first cascaded IP record, the IP address corresponding to the first IP string needs to be matched with each IP address in the second cascaded IP record, so as to determine whether the IP information corresponding to the IP address is stored in the second cascaded IP record, and if one IP address exists in the second cascaded IP record and the IP address corresponding to the first IP string are successfully matched, the IP information associated with the IP address in the second cascaded IP record can be used as the IP information of the IP address corresponding to the first IP string. And if any IP address does not exist in the second-level IP record and the IP address corresponding to the first IP character string is successfully matched, indicating that the IP address corresponding to the first IP character string does not exist in the second-level IP record.
Illustratively, taking a certain IP address as 45.115.45.3 as an example, according to the slicing reference of the mask bits 24, the IP address is sliced by bit in the order from left to right, the IP string "45.115.45" is obtained, the IP string is matched with each IP string in the C-domain dictionary table (i.e. the first cascaded IP record), if the matching of an IP character string in the C domain dictionary table and the IP character string is successful, determining that the IP character string exists in the C domain dictionary table, determining whether the IP character string belongs to the whole IP section, or determining whether there is IP information associated with the first IP string in the C-domain dictionary table, if yes, the IP information (for example, continental region 001) corresponding to the IP character string can be directly obtained from the C-domain dictionary table, that is, the value "continental region 001" is obtained, and thus, matching for the IP address is completed. Or, taking an IP address as 47.132.44.3 for example, according to the dividing reference of mask bits 24, dividing the IP address by bit from left to right in order to obtain an IP character string "47.132.44", matching the IP character string with each IP character string in the C-domain dictionary table, if an IP character string in the C-domain dictionary table is successfully matched with the IP character string, determining that the IP character string exists in the C-domain dictionary table, and determining whether the IP character string belongs to the whole IP field, or determining whether IP information associated with the first IP character string exists in the C-domain dictionary table, if not, determining that the IP character string belongs to the non-whole IP field, and performing a second-stage matching between the IP address and each IP address in the D-domain dictionary table, thereby determining whether IP information corresponding to the IP address exists in the D-domain dictionary table, if an IP address exists in the D-domain dictionary table, and the IP address is successfully matched, then the IP information (for example, the continental region 009) corresponding to the IP address can be obtained, that is, the value "continental region 009" is obtained. Or, taking 47.132.44.1 as an example of a certain IP address, according to the slicing reference of the mask bits 24, slicing the IP address by bit from left to right, the IP character string '47.132.44' can be obtained, the IP character string is matched with each IP character string in the C domain dictionary table, if the matching of an IP character string in the C domain dictionary table and the IP character string is successful, determining that the IP character string exists in the C domain dictionary table, determining whether the IP character string belongs to the whole IP section, or determining whether there is IP information associated with the first IP string in the C-domain dictionary table, if not, the IP character string is known to belong to the non-integral IP section, the second-stage matching is required to be carried out on the IP address and each IP address in the D domain dictionary table, but the IP address "47.132.44.1" does not exist in the D domain dictionary table, therefore, it is determined that the matching fails for the IP address "47.132.44.1" in the D domain dictionary table. Alternatively, taking an IP address as 46.0.0.0 for example, an IP string "46.0.0" may be obtained by bit-wise splitting the IP address in order from left to right according to the split reference of the mask bits 24, and the IP string is matched with each IP string in the C-domain dictionary table, but the IP string "46.0.0" does not exist in the C-domain dictionary table, and therefore, it is determined that the matching for the IP string "46.0.0" in the C-domain dictionary table fails.
The above embodiment shows that, in the prior art, when the IP information corresponding to the IP address is queried, the IP address needs to be converted for matching or directly matched, but all the problems exist in that a certain time is consumed for matching the IP address, so that the query efficiency of the IP information is low. Aiming at the problem, the technical scheme of the invention is to divide the IP address according to the mask bit instead of adding different weights after converting the IP address, so that the time overhead can be effectively reduced, the hierarchical query in the second-level-connection-type IP record can be further carried out only on the IP address without the associated IP information in the first-level-connection-type IP record, and the corresponding IP information can be timely and accurately queried only in the first-level-connection-type IP record aiming at the IP address with the associated IP information in the first-level-connection-type IP record, so that the storage overhead of the IP address can be effectively reduced, and the query efficiency of the IP information can be effectively improved. Specifically, when an IP information query request for any IP address is detected, the corresponding IP address can be analyzed from the IP information query request, and according to the set mask bits, bit-by-bit segmentation processing can be performed on the IP address to obtain the first IP character string, so that time consumed by adding different weights after converting the IP address can be saved. Determining whether the first IP character string exists in the first cascaded IP record, which is equivalent to performing first-stage matching on the IP address, if it is determined that the first IP character string exists in the first cascaded IP record but no IP information associated with the first IP character string exists, matching the IP address corresponding to the first IP character string with each IP address in the second cascaded IP record, and determining the IP information corresponding to the IP address when the matching is successful, that is, performing second-stage query on the IP address corresponding to the first IP character string only under the precondition that a certain first IP character string is stored in the first cascaded IP record but no IP information associated with the first IP character string is stored, so that query time for the IP address corresponding to the IP information associated with the first IP character string and a certain first IP character string is stored in the first cascaded IP record can be reduced (because the first cascaded IP record stores a certain first IP character string and stores IP address corresponding to the IP information associated with the first IP character string) The IP record stores a certain first IP character string and stores the IP address corresponding to the IP information associated with the first IP character string, only the first-level query is carried out), and the expense for storing a large number of single IP addresses can be effectively reduced. Therefore, the scheme can effectively save the time consumed by taking different weights for addition after the IP address is converted by segmenting according to the mask bit, and only carries out the second-stage query on the IP address corresponding to the IP information which is not stored with the first IP character string but stored with a certain first IP character string in the first cascade type IP record, thereby effectively improving the query efficiency of the IP information.
Based on the same technical concept, fig. 3 exemplarily shows an IP information query apparatus provided by an embodiment of the present invention, and the apparatus can execute a flow of an IP information query method.
As shown in fig. 3, the apparatus includes:
a detecting unit 301, configured to determine, when an IP information query request for any network protocol IP address is detected, a corresponding IP address from the IP information query request;
the processing unit 302 is configured to perform bitwise segmentation processing on the IP address according to a set mask bit, and determine a first IP character string; determining whether the first cascade IP character string exists in a first cascade IP record; if yes, matching the IP address with each IP address in the second cascade type IP record when the first cascade type IP record is determined to have no IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
Optionally, the processing unit 302 is further configured to:
and when determining that the IP information associated with the first IP character string exists in the first cascade type IP record, determining the IP information as the IP information corresponding to the IP address.
Optionally, the first cascaded IP record is used to indicate that a first level query is performed for an IP address; the second cascade IP record is used for indicating second-stage query aiming at the IP address; the second level query belongs to a hierarchical query of the first level query.
Optionally, the processing unit 302 is specifically configured to:
performing bit-wise segmentation processing on the IP address in a preset direction according to the set mask bit to obtain the first IP character string which accords with the set mask bit; wherein, the preset direction is from left to right or from right to left.
Optionally, the processing unit 302 is specifically configured to:
if the set mask bit is 24, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address; or, performing bitwise cutting processing on the segment D of the IP address in the sequence from right to left to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address;
if the set mask bit is 16, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A and the segment B of the IP address; or, performing bitwise cutting processing on the segment C and the segment D of the IP address in the order from right to left to obtain the first IP character string consisting of the segment A and the segment B of the IP address.
Optionally, the processing unit 302 is specifically configured to:
acquiring each IP address with the attribute of the whole IP section, each IP information corresponding to each IP address with the attribute of the whole IP section, each IP address without the attribute of the whole IP section and each IP information corresponding to each IP address without the attribute of the whole IP section from an IP home database;
according to set mask bits, performing bit-by-bit segmentation processing on the IP addresses with the integral IP section attribute and the IP addresses without the integral IP section attribute respectively to obtain second IP character strings corresponding to the IP addresses with the integral IP section attribute and second IP character strings corresponding to the IP addresses without the integral IP section attribute;
storing the second IP character strings corresponding to the IP addresses with the integral IP section attribute, the IP information corresponding to the IP addresses with the integral IP section attribute and the second IP character strings corresponding to the IP addresses without the integral IP section attribute in the first-level IP record, and storing the IP addresses without the integral IP section attribute and the IP information corresponding to the IP addresses without the integral IP section attribute in the second-level IP record.
Optionally, the processing unit 302 is specifically configured to:
and sequentially matching the first IP character string with each second IP character string in the first cascade type IP record in a preset matching mode, so as to determine whether the first IP character string exists in the first cascade type IP record.
Based on the same technical concept, an embodiment of the present invention further provides a computing device, as shown in fig. 4, including at least one processor 401 and a memory 402 connected to the at least one processor, where a specific connection medium between the processor 401 and the memory 402 is not limited in the embodiment of the present invention, and the processor 401 and the memory 402 are connected through a bus in fig. 4 as an example. The bus may be divided into an address bus, a data bus, a control bus, etc.
In the embodiment of the present invention, the memory 402 stores instructions executable by the at least one processor 401, and the at least one processor 401 may execute the steps included in the IP information querying method by executing the instructions stored in the memory 402.
The processor 401 is a control center of the computing device, and may be connected to various parts of the computing device through various interfaces and lines, and may perform data processing by executing or executing instructions stored in the memory 402 and calling data stored in the memory 402. Optionally, the processor 401 may include one or more processing units, and the processor 401 may integrate an application processor and a modem processor, where the application processor mainly processes an operating system, a user interface, an application program, and the like, and the modem processor mainly processes an issued instruction. It will be appreciated that the modem processor described above may not be integrated into the processor 401. In some embodiments, processor 401 and memory 402 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 401 may be a general-purpose processor, such as a Central Processing Unit (CPU), a digital signal processor, an Application Specific Integrated Circuit (ASIC), a field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof, configured to implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in connection with the embodiment of the IP information query method may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
Memory 402, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 402 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and so on. The memory 402 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 402 of embodiments of the present invention may also be circuitry or any other device capable of performing a storage function to store program instructions and/or data.
Based on the same technical concept, the embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the computer program causes the computing device to execute the steps of the IP information query method.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present application and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. An IP information query method, comprising:
when an IP information query request aiming at any network protocol IP address is detected, determining a corresponding IP address from the IP information query request;
according to a set mask bit, carrying out bit-by-bit segmentation processing on the IP address to determine a first IP character string;
determining whether the first cascade IP character string exists in a first cascade IP record;
if yes, matching the IP address with each IP address in the second cascade type IP record when the first cascade type IP record is determined to have no IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
2. The method of claim 1, wherein the method further comprises:
and when determining that the IP information associated with the first IP character string exists in the first cascade type IP record, determining the IP information as the IP information corresponding to the IP address.
3. The method of claim 1, wherein the first cascaded IP record is to indicate a first level query is made for an IP address; the second cascade IP record is used for indicating second-stage query aiming at the IP address; the second level query belongs to a hierarchical query of the first level query.
4. The method as claimed in claim 1, wherein said performing a bit-wise splitting process on said IP address according to a set mask bit to determine a first IP string comprises:
performing bit-wise segmentation processing on the IP address in a preset direction according to the set mask bit to obtain the first IP character string which accords with the set mask bit; wherein, the preset direction is from left to right or from right to left.
5. The method as claimed in claim 4, wherein said bit-slicing the IP address in a predetermined direction to obtain the first IP string corresponding to the set mask bit comprises:
if the set mask bit is 24, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address; or, performing bitwise cutting processing on the segment D of the IP address in the sequence from right to left to obtain the first IP character string consisting of the segment A, the segment B and the segment C of the IP address;
if the set mask bit is 16, performing bit-by-bit segmentation processing on the IP address in a left-to-right sequence to obtain the first IP character string consisting of the segment A and the segment B of the IP address; or, performing bitwise cutting processing on the segment C and the segment D of the IP address in the order from right to left to obtain the first IP character string consisting of the segment A and the segment B of the IP address.
6. The method of claim 3, wherein the first cascaded IP record and the second cascaded IP record are determined by:
acquiring each IP address with the attribute of the whole IP section, each IP information corresponding to each IP address with the attribute of the whole IP section, each IP address without the attribute of the whole IP section and each IP information corresponding to each IP address without the attribute of the whole IP section from an IP home database;
according to set mask bits, performing bit-by-bit segmentation processing on the IP addresses with the integral IP section attribute and the IP addresses without the integral IP section attribute respectively to obtain second IP character strings corresponding to the IP addresses with the integral IP section attribute and second IP character strings corresponding to the IP addresses without the integral IP section attribute;
storing the second IP character strings corresponding to the IP addresses with the integral IP section attribute, the IP information corresponding to the IP addresses with the integral IP section attribute and the second IP character strings corresponding to the IP addresses without the integral IP section attribute in the first-level IP record, and storing the IP addresses without the integral IP section attribute and the IP information corresponding to the IP addresses without the integral IP section attribute in the second-level IP record.
7. The method of claim 6, wherein determining whether the first IP string is present in a first cascaded IP record comprises:
and sequentially matching the first IP character string with each second IP character string in the first cascade type IP record in a preset matching mode, so as to determine whether the first IP character string exists in the first cascade type IP record.
8. An IP information inquiry apparatus, comprising:
the device comprises a detection unit, a processing unit and a processing unit, wherein the detection unit is used for determining a corresponding IP address from an IP information query request when the IP information query request aiming at any network protocol IP address is detected;
the processing unit is used for carrying out bit-by-bit segmentation processing on the IP address according to a set mask bit to determine a first IP character string; determining whether the first cascade IP character string exists in a first cascade IP record; if yes, matching the IP address with each IP address in the second cascade type IP record when the first cascade type IP record is determined to have no IP information associated with the first IP character string, and determining the IP information corresponding to the IP address when the matching is successful.
9. A computing device comprising at least one processor and at least one memory, wherein the memory stores a computer program that, when executed by the processor, causes the processor to perform the method of any of claims 1 to 7.
10. A computer-readable storage medium, storing a computer program executable by a computing device, the program, when run on the computing device, causing the computing device to perform the method of any of claims 1 to 7.
CN202111621861.8A 2021-12-28 2021-12-28 IP information query method and device Pending CN114357274A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111621861.8A CN114357274A (en) 2021-12-28 2021-12-28 IP information query method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111621861.8A CN114357274A (en) 2021-12-28 2021-12-28 IP information query method and device

Publications (1)

Publication Number Publication Date
CN114357274A true CN114357274A (en) 2022-04-15

Family

ID=81102587

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111621861.8A Pending CN114357274A (en) 2021-12-28 2021-12-28 IP information query method and device

Country Status (1)

Country Link
CN (1) CN114357274A (en)

Similar Documents

Publication Publication Date Title
CN108255958B (en) Data query method, device and storage medium
CN106033416B (en) Character string processing method and device
CN110019218B (en) Data storage and query method and equipment
US11347787B2 (en) Image retrieval method and apparatus, system, server, and storage medium
CN107784110B (en) Index establishing method and device
CN106326475B (en) Efficient static hash table implementation method and system
CN104794123A (en) Method and device for establishing NoSQL database index for semi-structured data
CN114398315A (en) Data storage method, system, storage medium and electronic equipment
CN109670153B (en) Method and device for determining similar posts, storage medium and terminal
CN113821630B (en) Data clustering method and device
CN113408660A (en) Book clustering method, device, equipment and storage medium
CN116126997B (en) Document deduplication storage method, system, device and storage medium
CN108776705B (en) Text full-text accurate query method, device, equipment and readable medium
CN114357274A (en) IP information query method and device
CN107832341B (en) AGNSS user duplicate removal statistical method
CN113742344A (en) Method and device for indexing power system data
CN110046180B (en) Method and device for locating similar examples and electronic equipment
CN113407576A (en) Data association method and system based on dimension reduction algorithm
CN111858609A (en) Fuzzy query method and device for block chain
CN111639099A (en) Full-text indexing method and system
CN112860712B (en) Block chain-based transaction database construction method, system and electronic equipment
CN111460088A (en) Similar text retrieval method, device and system
CN115048543B (en) Image similarity judgment method, image searching method and device
CN117729176B (en) Method and device for aggregating application program interfaces based on network address and response body
CN113407656B (en) Method and equipment for fast online log clustering

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination