WO2022142499A1 - Method and apparatus for determining region to which ip address belongs, and electronic device and storage medium - Google Patents

Method and apparatus for determining region to which ip address belongs, and electronic device and storage medium Download PDF

Info

Publication number
WO2022142499A1
WO2022142499A1 PCT/CN2021/119296 CN2021119296W WO2022142499A1 WO 2022142499 A1 WO2022142499 A1 WO 2022142499A1 CN 2021119296 W CN2021119296 W CN 2021119296W WO 2022142499 A1 WO2022142499 A1 WO 2022142499A1
Authority
WO
WIPO (PCT)
Prior art keywords
address
integer value
starting
ending
target
Prior art date
Application number
PCT/CN2021/119296
Other languages
French (fr)
Chinese (zh)
Inventor
谢建乐
万月亮
火一莽
Original Assignee
北京锐安科技有限公司
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 北京锐安科技有限公司 filed Critical 北京锐安科技有限公司
Publication of WO2022142499A1 publication Critical patent/WO2022142499A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/29Geographical information databases

Definitions

  • the embodiments of the present application relate to the field of Internet technologies, for example, to a method, apparatus, electronic device, and storage medium for determining an area to which an IP address belongs.
  • IP Internet Protocol
  • the Internet is becoming more and more developed. With the explosive growth of the number of addresses and the increasing frequency of IP address queries, it is difficult for related technologies to ensure the search speed and search results when determining the area to which the address belongs based on the IP address. are optimal. Therefore, there is no method in the related art that can simply, conveniently and accurately determine the area to which the IP address belongs.
  • the present application provides a method, device, electronic device and storage medium for determining the area to which an IP address belongs, so as to realize the simple, convenient and accurate determination of the area to which an IP address belongs.
  • An embodiment of the present application provides a method for determining an area to which an IP address belongs.
  • the method includes: obtaining a target IP address; converting the target IP address into an unsigned integer value by adopting a preset rule; according to the unsigned integer value The relationship with the predetermined starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, all starting address integer values in the starting address integer value sequence and the All the termination address integer values in the termination address integer value sequence are obtained by converting the start addresses and termination addresses of multiple IP address ranges that do not intersect with each other by using the preset rule.
  • the embodiment of the present application also provides a device for determining an area to which an IP address belongs, the device comprising: a target address acquisition module, configured to obtain a target IP address; a conversion module, configured to adopt a preset rule for the target IP address, convert into an unsigned integer value; the target area determination module is configured to determine the area to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the integer value of the ending address; wherein , all starting address integer values in the starting address integer value sequence and all ending address integer values in the ending address integer value sequence are the starting addresses and ending addresses of multiple IP address ranges that do not cross each other. obtained by converting the preset rules.
  • An embodiment of the present application further provides an electronic device, the device includes: one or more processors; a storage device configured to store one or more programs, when the one or more programs are stored by the one or more programs Each processor executes, so that the one or more processors implement any one of the methods for determining a region to which an IP address belongs provided by the foregoing embodiments.
  • Embodiments of the present application further provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements any of the methods for determining a region to which an IP address belongs provided by the foregoing embodiments.
  • FIG. 1 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 1 of the present application;
  • FIG. 2 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 2 of the present application;
  • FIG. 3 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 3 of the present application;
  • FIG. 4 is a schematic diagram of a device for determining an area to which an IP address belongs according to Embodiment 4 of the present application;
  • FIG. 5 is a schematic diagram of an electronic device according to Embodiment 5 of the present application.
  • FIG. 1 is a flowchart of a method for determining an area to which an IP address belongs according to Embodiment 1 of the present application.
  • the embodiments of the present application are applicable to the case of determining the area to which the IP address belongs.
  • the method may be performed by a device for determining the area to which the IP address belongs, the device may be implemented in software and/or hardware, and configured in an electronic device, which may be a mobile terminal or a fixed terminal.
  • the method for determining a region to which an IP address belongs includes the following steps.
  • An IP address refers to an address assigned to each host connected to the Internet. Users can communicate with other hosts on the Internet through the host and the IP address.
  • the target IP address refers to the IP address to be determined for the area to which it belongs.
  • the IP address may be an Internet Protocol version 4 (Internet Protocol version 4, IPv4) address, or may be an Internet Protocol version 6 (Internet Protocol version 6, IPv6) address, which is not limited in this embodiment of the present application.
  • an IP address has a length of 32 bits and is divided into 4 segments, each segment is 8 bits, represented by decimal numbers, each segment number ranges from 0 to 255, and segments are separated by dots.
  • the destination IP address is 192.168.1.1.
  • the preset rule refers to a predetermined rule that converts the target IP address to obtain an unsigned integer value that is beneficial for statistics and analysis.
  • An unsigned integer value refers to an integer value without a sign bit, and the unsigned integer value can be represented in either binary, octal, or decimal or hexadecimal.
  • Dotted data refers to multiple numeric fields in an IP address separated by dots.
  • the two-digit hexadecimal value of each dotted data in the multiple dotted data refers to the hexadecimal conversion of the digital fields separated by dots of the IP address respectively, to obtain the hexadecimal value in the multiple dotted data.
  • the two-digit hexadecimal value of each dotted data refers to the hexadecimal conversion of the digital fields separated by dots of the IP address respectively, to obtain the hexadecimal value in the multiple dotted data.
  • Concatenation means that after removing the dot in the middle of the IP address, multiple two-digit hexadecimal values of multiple dotted data are sequentially connected from left to right to obtain the integer value of the IP address.
  • the target IP address is converted to obtain a target IP address in the form of an unsigned integer value, so that the target IP address can be counted and analyzed by a numerical method.
  • S130 Determine the area to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence; wherein, all starting address integer values in the starting address integer value sequence All termination address integer values in the integer value sequence of the termination address and the termination address are obtained by converting the start address and the termination address of multiple IP address ranges that do not intersect with each other by using a preset rule.
  • the start address and the end address exist correspondingly, and an IP address range is formed by the start address and the end address, and this IP address range represents an area.
  • Non-intersecting means that for the start address and end address of an IP address range, the network address where the start address and end address are located (the IP address is composed of two parts, the network address and the host address) needs to be consistent. That is to say, only if the network address where the start address and the end address are located are consistent, it means that the start address and the end address are corresponding, and the IP address range indicated by this is correct.
  • the network address refers to the logical address that a node on the Internet has in the network, which can address the node, while the host address refers to the part on the right side of the IP address used to identify the host itself. All IP addresses in the same IP address range may be distributed in the same area, for example, belong to the same cell, the same urban area or the same province.
  • the starting address integer value sequence refers to the starting address integer value sequence obtained by sorting multiple starting address integer values;
  • the ending address integer value sequence refers to the ending address integer value sequence obtained by sorting multiple ending address integer values.
  • the starting address integer values in the starting address integer value sequence correspond one-to-one with the ending address integer values in the ending address integer value sequence.
  • the starting address integer value sequence and the ending address integer value sequence may be pre-determined, stored in the memory, and called when needed.
  • the target IP address is converted into an unsigned integer value by adopting a preset rule, so as to facilitate searching for the target IP address.
  • the integer value sequence is a sequence consisting of multiple starting address integer values and multiple ending address integer values respectively, and multiple starting address integer values and multiple ending address integer values are composed of multiple IP address ranges that do not intersect each other.
  • the start address and end address of the IP address are converted using preset rules, which ensures the consistency of the conversion, and the multiple IP address ranges that do not intersect each other ensure that the areas where the multiple IP address ranges are located will not overlap, so that the According to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence, the area to which the target IP address belongs is accurately determined.
  • FIG. 2 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 2 of the present application. This embodiment is based on the above-mentioned embodiment, and describes the above-mentioned scheme.
  • each IP address range in the at least two IP address ranges corresponds to an area; determine the start address and end address of each IP address range; combine the start address and the end address Using the preset rule conversion, the starting address integer value and the ending address integer value of each IP address range are obtained; the starting address integer values of the at least two IP address ranges are in ascending order.
  • Sort to obtain a sequence of integer values of starting addresses; and sort the integer values of ending addresses of the at least two IP address ranges in ascending order to obtain a sequence of integer values of ending addresses", so as to improve the sequence of integer values of starting addresses. and terminates the process of address integer value sequence determination.
  • a method for determining an area to which an IP address belongs includes the following steps.
  • the at least two IP address ranges that do not overlap each other ensure that the areas where the at least two IP address ranges are located will not overlap.
  • the method before acquiring at least two IP address ranges that do not intersect each other, the method further includes: detecting whether the at least two IP address ranges overlap; if it is detected that the at least two IP address ranges overlap, Then, a prompt message that there is a crossover error is generated for the staff to modify the crossover error.
  • the prompt information includes the starting address information and the ending address information indicating that there is a crossover, so that the staff can make targeted corrections to the crossover error.
  • each IP address range has a starting address and an ending address, based on the above multiple IP address ranges, multiple starting addresses and ending addresses can be determined .
  • the predetermined integer value of the starting address and the integer value of the ending address are the same as the rules for unsigned integer value conversion of the target IP address, which ensures the consistency of the conversion and is conducive to the accurate search of the target IP address.
  • S260 Sort the integer values of the starting addresses of the at least two IP address ranges in ascending order to obtain a sequence of integer values of the starting addresses; and sort the integer values of the ending addresses of the at least two IP address ranges according to the following order: Sort from small to large to get a sequence of terminating address integer values.
  • the starting address integer value sequence and the starting address integer value sequence are obtained by arranging multiple starting address integer values and multiple ending address integer values in ascending order, which facilitates subsequent searching of the unsigned integer value represented by the target IP address.
  • S270 Load the sequence of integer values of the starting address into the continuous memory, and load the sequence of integer values of the ending address into the continuous memory.
  • Memory refers to persistent memory used to store a sequence of integer values for a starting address and a sequence of integer values for an ending address.
  • the memory may be a mobile hard disk, an optical disk, or the like, which is not limited in this embodiment of the present application.
  • S210 to S220 may be executed before S230 to 270, or S210 to S220 may be executed after S230 to S270 is executed.
  • the length of the starting address integer value sequence is 1, and correspondingly, the length of the ending address integer value sequence is also 1, and the starting address integer value sequence and the ending address integer value sequence are stored in an array , the obtained starting address array in the form of unsigned integers in ascending order is denoted as As, the obtained array of ending addresses in ascending order in the form of unsigned integers is denoted as Ae, and the array lengths of the arrays As and Ae are both l.
  • the starting address array and the ending address array are stored in the memory of the computer by means of memory mirroring.
  • the starting address array and the ending address array can be read as if they have all been loaded into the computer memory.
  • S280 Determine the region to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence; wherein, all starting address integer values in the starting address integer value sequence All termination address integer values in the integer value sequence of the termination address and the termination address are obtained by converting the start address and the termination address of multiple IP address ranges that do not intersect with each other by using a preset rule.
  • the predetermined starting address needs to be read from the memory.
  • the manner of reading the predetermined starting address integer value sequence and the ending address integer value sequence from the memory may refer to the following manner.
  • uint_t count //uint_t represents an unsigned integer type, and count represents the number of addresses
  • uint_t* is a pointer to unsigned integer type.
  • the embodiments of the present application describe the process of determining the integer value sequence of the starting address and the integer value sequence of the ending address.
  • the starting address and ending address of each IP address range are converted according to preset rules to obtain the starting address and ending address integer value of each IP address range. , and then arrange the starting address integer values and ending address integer values of multiple non-intersecting IP address ranges in ascending order to obtain the starting address integer value sequence and the starting address integer value sequence.
  • the relationship between the starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, the predetermined starting address integer value sequence and the ending address integer value sequence determine the area to which the target IP address belongs.
  • FIG. 3 is a flowchart of a method for determining an area to which an IP address belongs according to Embodiment 3 of the present application. This embodiment is based on the above-mentioned embodiment, and describes the above-mentioned scheme.
  • the operation "determining the region to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the integer value of the ending address” is described as "using the method of dichotomy to determine the integer value of the starting address.
  • the integer value of the starting address to be identified that is less than or equal to the unsigned integer value in the sequence; determine the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified; if the unsigned integer value is in the Between the integer value of the starting address to be identified and the integer value of the ending address to be identified, it is determined that the area to which the target IP address belongs is the same as the area of the IP address range of the integer value of the starting address to be identified.
  • the process of determining the area to which the IP address belongs is described as "using the method of dichotomy to determine the integer value of the starting address.
  • a method for determining an area to which an IP address belongs includes the following steps.
  • Dichotomy refers to a method of halving search, which can quickly search the data to be queried.
  • Using dichotomy to determine the starting address integer value to be identified that is less than or equal to the unsigned integer value in the starting address integer value sequence refers to finding the starting address closest to the unsigned integer value in the starting address integer value sequence. Integer value, and the starting address integer value needs to be less than the unsigned integer value. That is, the integer value of the starting address to be identified that needs to be determined in the integer value sequence of the starting address is the largest item less than or equal to the unsigned integer value.
  • search for the integer value sequence of the starting address of the next child If the value is less than the unsigned integer value, search for the integer value sequence of the starting address of the next child. If the integer value of the address recorded in the middle position is greater than the unsigned integer value, search for the integer value sequence of the starting address of the previous child. The above process is repeated until an address integer value that satisfies the condition is found, so that the search for the integer value of the starting address to be identified is successful.
  • the integer value of the ending address to be identified corresponds to the integer value of the starting address to be identified. From the position index of the integer value of the starting address to be identified in the integer value sequence of the starting address, the integer value of the ending address to be identified can be directly determined at the same position index of the integer value sequence of the ending address.
  • the IP address range is the same as the zone.
  • the unsigned integer value between the integer value of the starting address to be identified and the integer value of the ending address to be identified has the same network address as the integer value of the starting address to be identified and the integer value of the ending address to be identified, that is, an unsigned integer
  • the target IP address represented by the value is the same as the area represented by the integer value of the starting address to be identified, and the host where the target IP address is located is only one of the many hosts in the above area.
  • the determination of the area to which the target IP address belongs fails to be determined.
  • the failure to determine the area to which the target IP address belongs may be due to an error in the target IP address itself; or, there is an error in the predetermined start address integer value sequence and end address integer value sequence. After the determination of the area to which the target IP address belongs fails to be determined, an alarm can be alerted to the staff, and a work log is recorded for the target IP address for which the area determination is unsuccessful.
  • the staff periodically checks the work log, checks the target IP address, and checks the predetermined start address integer value sequence and end address integer value sequence to determine the cause of the error and make corresponding adjustments.
  • the embodiment of the present application obtains an unsigned integer value by converting the target IP address to be determined in the region to which it belongs. According to the relationship between the unsigned integer value and the predetermined starting address integer value sequence, the The binary search method determines the integer value of the starting address to be identified that is less than or equal to the unsigned integer value.
  • the integer value of the termination address according to the IP address range formed by the integer value of the starting address to be identified and the integer value of the ending address to be identified, to determine whether the unsigned integer value falls within the above IP address range, and if it is determined to fall within the above IP address range , the area to which the target IP address belongs is within the above IP address range; through the above solution, the effect of simply, conveniently and accurately determining the area to which the IP address belongs is achieved.
  • FIG. 4 is a schematic structural diagram of an apparatus for determining an area to which an IP address belongs according to Embodiment 4 of the present application.
  • an apparatus for determining an area to which an IP address belongs provided by an embodiment of the present application includes: a target address acquisition module 410 , a conversion module 420 , and a target area determination module 430 .
  • the target address obtaining module 410 is configured to obtain the target IP address; the conversion module 420 is configured to adopt a preset rule to convert the target IP address into an unsigned integer value; the target area determination module 430 is configured to The relationship between the integer value and the predetermined starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, all the starting address integer values in the starting address integer value sequence and the All the termination address integer values in the termination address integer value sequence are obtained by converting the start addresses and termination addresses of multiple IP address ranges that do not intersect with each other by using the preset rule.
  • the embodiment of the present application obtains the target IP address, adopts preset rules for the target IP address, and converts the target IP address into an unsigned integer value, so as to facilitate the search for the target IP address.
  • the predetermined starting address integer value sequence and the ending address integer The value sequence is a sequence consisting of multiple starting address integer values and multiple ending address integer values, respectively, and multiple starting address integer values and multiple ending address integer values are the starting addresses of multiple non-intersecting IP address ranges.
  • the address and the termination address are converted by preset rules, which ensures the consistency of the conversion, and the multiple IP address ranges that do not cross each other ensure that the areas where the multiple IP address ranges are located will not overlap.
  • the relationship between the integer value and the predetermined starting address integer value sequence and ending address integer value sequence accurately determines the area to which the target IP address belongs, and achieves the effect of simply, conveniently and accurately determining the area to which the IP address belongs.
  • the preset rules include: performing hexadecimal conversion on each point data in the multiple point data of the IP address to obtain a two-digit hexadecimal value of each point data; The two hexadecimal values of the data are concatenated to obtain the integer value of the IP address.
  • the target area determination module includes: an address acquisition unit, configured to acquire at least two IP address ranges that do not intersect with each other; wherein, each IP address range corresponds to an area; and an address determination unit is configured to determine the starting point of each IP address range. starting address and ending address; an address conversion unit, configured to convert the starting address and the ending address using the preset rule, to obtain the starting address integer value and ending address integer value of each IP address range an address sorting unit, configured to sort the starting address integer values of the at least two IP address ranges in ascending order to obtain a sequence of starting address integer values; The termination address integer values of are sorted in ascending order to obtain the termination address integer value sequence.
  • the target area determination module further includes: a loading unit, configured to load the starting address integer value sequence into a continuous memory after obtaining the starting address integer value sequence and the ending address integer value sequence, and load the terminating address integer value sequence into a continuous memory. A sequence of address integer values is loaded into contiguous memory.
  • the target area determination module further includes: a detection unit, configured to detect whether the at least two IP address ranges intersect each other before acquiring at least two IP address ranges that do not intersect with each other; a prompt information generation unit, set to if If it is detected that the at least two IP address ranges overlap, prompt information that there is an overlap error is generated, so that the staff can revise the overlap error.
  • a detection unit configured to detect whether the at least two IP address ranges intersect each other before acquiring at least two IP address ranges that do not intersect with each other
  • a prompt information generation unit set to if If it is detected that the at least two IP address ranges overlap, prompt information that there is an overlap error is generated, so that the staff can revise the overlap error.
  • the target area determination module further includes: a start address identification unit, configured to use a binary method to determine the start address integer value to be identified that is less than or equal to the unsigned integer value in the start address integer value sequence; the end address identification unit, be set to determine the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified; the target area determination unit is set to if the unsigned integer value is between the integer value of the starting address to be identified and the integer value of the starting address to be identified If the integer value of the end address is identified, it is determined that the area to which the target IP address belongs is the same as the area of the IP address range of the integer value of the start address to be identified.
  • the target area determination unit is further configured to fail to determine the area to which the target IP address belongs if the unsigned integer value is not between the integer value of the starting address to be identified and the integer value of the ending address to be identified.
  • the apparatus for determining the area to which the IP address belongs provided by the embodiment of the present application can execute the method for determining the area to which the IP address belongs provided by any embodiment of the present application, and has functional modules corresponding to the execution method.
  • FIG. 5 is a schematic structural diagram of an electronic device according to Embodiment 5 of the present application.
  • the apparatus includes a processor 510 , a memory 520 , an input device 530 and an output device 540 .
  • the number of processors 510 in the device can be one or more, and one processor 510 is taken as an example in FIG. 5; the processor 510, the memory 520, the input device 530 and the output device 540 in the device can be connected through a bus or other means, In FIG. 5, the connection through the bus is taken as an example.
  • the input device 530 is configured to receive the target IP address.
  • the output device 540 is configured to output the area to which the target IP address belongs.
  • the processor 510 can convert the target IP address into an unsigned integer value according to the target IP address input by the input device 530 using a preset rule for the target IP address; it can also be based on the unsigned integer value and a predetermined starting point.
  • the relationship between the starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; the area to which the target IP address belongs may also be transmitted to the output device 540 .
  • the memory 520 can be configured to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the method for determining the region to which the IP address belongs in the embodiments of the present application (for example, the IP address).
  • the processor 510 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 520 , that is, to implement the above-mentioned method for determining the area to which the IP address belongs.
  • the memory 520 may mainly include a stored program area and a stored data area, wherein the stored program area may store an operating system, an application program required for at least one function; the stored data area may store data created according to the use of the terminal, etc. In the example, the destination IP address, the starting address integer value sequence and the ending address integer value sequence, etc.). Additionally, memory 520 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, memory 520 may also include memory located remotely from processor 510, which may be connected to the device through a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
  • the input device 530 may be configured to receive input numerical or character information, and to generate key signal input related to user settings and function control of the device.
  • the output device 540 may include a display device such as a display screen.
  • Embodiment 6 of the present application further provides a storage medium containing computer-executable instructions, where the computer-executable instructions are used to execute a method for determining a region to which an IP address belongs when executed by a computer processor, the method comprising: obtaining a target IP address; use preset rules to convert the target IP address into an unsigned integer value; determine the target IP according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the sequence of integer values of the ending address The region to which the address belongs; wherein, all the starting address integer values in the starting address integer value sequence and all ending address integer values in the ending address integer value sequence are the starting points of multiple non-intersecting IP address ranges.
  • the start address and end address are obtained by converting using the preset rules.
  • the present application can be implemented by means of software and general hardware, and certainly can also be implemented by hardware.
  • the technical solution of the present application 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 a floppy disk of a computer, a read-only memory (Read-Only Memory, ROM), Random Access Memory (Random Access Memory, RAM), flash memory (FLASH), hard disk or optical disk, etc., including multiple instructions to make a computer device (which may be a personal computer, server, or network device, etc.) The method described in each embodiment.
  • the multiple units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be realized, that is, Yes; in addition, the names of multiple functional units are only for the convenience of distinguishing from each other, and are not used to limit the protection scope of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Remote Sensing (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

Disclosed are a method and apparatus for determining a region to which an IP address belongs, and an electronic device and a storage medium. The method comprises: acquiring a target IP address; converting the target IP address into an unsigned integer value by using a pre-set rule; and according to the relationship between the unsigned integer value and a pre-determined start address integer value sequence and end address integer value sequence, determining a region to which the target IP address belongs, wherein all start address integer values in the start address integer value sequence and all end address integer values in the end address integer value sequence are obtained by means of converting, by using the pre-set rule, start addresses and end addresses in a plurality of IP address ranges which do not intersect with one another.

Description

IP地址所属区域的确定方法、装置、电子设备及存储介质Method, device, electronic device and storage medium for determining the area to which an IP address belongs
本申请要求在2020年12月28日提交中国专利局、申请号为202011581661.X的中国专利申请的优先权,该申请的全部内容通过引用结合在本申请中。This application claims the priority of the Chinese Patent Application No. 202011581661.X filed with the China Patent Office on December 28, 2020, the entire contents of which are incorporated herein by reference.
技术领域technical field
本申请实施例涉及互联网技术领域,例如涉及一种IP地址所属区域的确定方法、装置、电子设备及存储介质。The embodiments of the present application relate to the field of Internet technologies, for example, to a method, apparatus, electronic device, and storage medium for determining an area to which an IP address belongs.
背景技术Background technique
社会已经进入一个信息量爆炸的阶段,然而对于社会治理、调查和统计等需求而言,迫切需要及时且准确的信息,其中就有针对信息中的网际互连协议(Internet Protocol,IP)地址,需要将IP地址归类为其所属的区域,比如一个国家,一个省/市/区/县,甚至学校或单位等。Society has entered a stage of information explosion. However, for social governance, investigation and statistics, there is an urgent need for timely and accurate information, including Internet Protocol (IP) addresses in information, IP addresses need to be classified into the region to which they belong, such as a country, a province/city/district/county, or even a school or unit.
互联网日益发达,随着地址的数目呈现爆炸式增长,并且对IP地址的查询频率也越来越高,相关技术在依据IP地址确定该地址所属区域时,很难保证在查找速度以及查找结果上都是最优的。因此,相关技术中还没有一种方法能够简单、方便并准确的确定IP地址的所属区域。The Internet is becoming more and more developed. With the explosive growth of the number of addresses and the increasing frequency of IP address queries, it is difficult for related technologies to ensure the search speed and search results when determining the area to which the address belongs based on the IP address. are optimal. Therefore, there is no method in the related art that can simply, conveniently and accurately determine the area to which the IP address belongs.
发明内容SUMMARY OF THE INVENTION
本申请提供一种IP地址所属区域的确定方法、装置、电子设备及存储介质,以实现简单、方便并准确的确定IP地址的所属区域。The present application provides a method, device, electronic device and storage medium for determining the area to which an IP address belongs, so as to realize the simple, convenient and accurate determination of the area to which an IP address belongs.
本申请实施例提供了一种IP地址所属区域的确定方法,该方法包括:获取目标IP地址;对所述目标IP地址采用预设规则,转换成无符号整数值;根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定所述目标IP地址的所属区域;其中,所述起始地址整数值序列中的全部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换得到的。An embodiment of the present application provides a method for determining an area to which an IP address belongs. The method includes: obtaining a target IP address; converting the target IP address into an unsigned integer value by adopting a preset rule; according to the unsigned integer value The relationship with the predetermined starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, all starting address integer values in the starting address integer value sequence and the All the termination address integer values in the termination address integer value sequence are obtained by converting the start addresses and termination addresses of multiple IP address ranges that do not intersect with each other by using the preset rule.
本申请实施例还提供了一种IP地址所属区域的确定装置,该装置包括:目标地址获取模块,设置为获取目标IP地址;转换模块,设置为对所述目标IP地址采用预设规则,转换成无符号整数值;目标区域确定模块,设置为根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定所述目标IP地址的所属区域;其中,所述起始地址整数值序列中的全 部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换得到的。The embodiment of the present application also provides a device for determining an area to which an IP address belongs, the device comprising: a target address acquisition module, configured to obtain a target IP address; a conversion module, configured to adopt a preset rule for the target IP address, convert into an unsigned integer value; the target area determination module is configured to determine the area to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the integer value of the ending address; wherein , all starting address integer values in the starting address integer value sequence and all ending address integer values in the ending address integer value sequence are the starting addresses and ending addresses of multiple IP address ranges that do not cross each other. obtained by converting the preset rules.
本申请实施例还提供了一种电子设备,所述设备包括:一个或多个处理器;存储装置,设置为存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现上述实施例所提供的任意一种IP地址所属区域的确定方法。An embodiment of the present application further provides an electronic device, the device includes: one or more processors; a storage device configured to store one or more programs, when the one or more programs are stored by the one or more programs Each processor executes, so that the one or more processors implement any one of the methods for determining a region to which an IP address belongs provided by the foregoing embodiments.
本申请实施例还提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现上述实施例所提供的任意一种IP地址所属区域的确定方法。Embodiments of the present application further provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements any of the methods for determining a region to which an IP address belongs provided by the foregoing embodiments.
附图说明Description of drawings
图1是本申请实施例一提供的一种IP地址所属区域的确定方法的流程图;1 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 1 of the present application;
图2是本申请实施例二提供的一种IP地址所属区域的确定方法的流程图;2 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 2 of the present application;
图3是本申请实施例三提供的一种IP地址所属区域的确定方法的流程图;3 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 3 of the present application;
图4是本申请实施例四提供的一种IP地址所属区域的确定装置的示意图;4 is a schematic diagram of a device for determining an area to which an IP address belongs according to Embodiment 4 of the present application;
图5是本申请实施例五提供的一种电子设备的示意图。FIG. 5 is a schematic diagram of an electronic device according to Embodiment 5 of the present application.
具体实施方式Detailed ways
下面结合附图和实施例对本申请进行说明。可以理解的是,此处所描述的实施例仅仅用于解释本申请,而非对本申请的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与本申请相关的部分而非全部结构。The present application will be described below with reference to the accompanying drawings and embodiments. It should be understood that the embodiments described herein are only used to explain the present application, but not to limit the present application. In addition, it should be noted that, for the convenience of description, the drawings only show some but not all the structures related to the present application.
实施例一Example 1
图1为本申请实施例一提供的一种IP地址所属区域的确定方法的流程图。本申请实施例可适用于对IP地址所属区域进行确定的情况。该方法可以由一种IP地址所属区域的确定装置来执行,该装置可以由软件和/或硬件的方式实现,并配置于电子设备中,该电子设备可以是移动终端或固定终端。FIG. 1 is a flowchart of a method for determining an area to which an IP address belongs according to Embodiment 1 of the present application. The embodiments of the present application are applicable to the case of determining the area to which the IP address belongs. The method may be performed by a device for determining the area to which the IP address belongs, the device may be implemented in software and/or hardware, and configured in an electronic device, which may be a mobile terminal or a fixed terminal.
参见图1,本申请实施例提供的IP地址所属区域的确定方法包括如下步骤。Referring to FIG. 1 , the method for determining a region to which an IP address belongs provided by an embodiment of the present application includes the following steps.
S110、获取目标IP地址。S110. Obtain a target IP address.
IP地址是指给每个连接在互联网上的主机分配的一个地址,用户通过主机以及IP地址可以与互联网中的其他主机通信。An IP address refers to an address assigned to each host connected to the Internet. Users can communicate with other hosts on the Internet through the host and the IP address.
目标IP地址是指待进行所属区域确定的IP地址。该IP地址可以网际协议版本4(Internet Protocol version 4,IPv4)地址,也可以是网际协议版本6(Internet  Protocol version 6,IPv6)地址,本申请实施例对此不做限定。The target IP address refers to the IP address to be determined for the area to which it belongs. The IP address may be an Internet Protocol version 4 (Internet Protocol version 4, IPv4) address, or may be an Internet Protocol version 6 (Internet Protocol version 6, IPv6) address, which is not limited in this embodiment of the present application.
以IPv4地址为例,IP地址的长度为32位,分为4段,每段8位,用十进制数字表示,每段数字范围为0~255,段与段之间用点分隔开。例如,目标IP地址是192.168.1.1。Taking an IPv4 address as an example, an IP address has a length of 32 bits and is divided into 4 segments, each segment is 8 bits, represented by decimal numbers, each segment number ranges from 0 to 255, and segments are separated by dots. For example, the destination IP address is 192.168.1.1.
S120、对目标IP地址采用预设规则,转换成无符号整数值。S120. Use a preset rule to convert the target IP address into an unsigned integer value.
预设规则是指预先规定的,对目标IP地址进行转换,以得到利于进行统计与分析的无符号整数值的规则。而无符号整数值是指不带符号位的整数值,该无符号整数值既可以用二进制表示,也可以用八进制表示,还可以用十进制或十六进制表示。The preset rule refers to a predetermined rule that converts the target IP address to obtain an unsigned integer value that is beneficial for statistics and analysis. An unsigned integer value refers to an integer value without a sign bit, and the unsigned integer value can be represented in either binary, octal, or decimal or hexadecimal.
点分数据是指IP地址中用点分隔开的多个数字段。Dotted data refers to multiple numeric fields in an IP address separated by dots.
多个点分数据中的每个点分数据的两位十六进制数值是指,分别对IP地址用点分隔开的数字段进行十六进制转换,得到多个点分数据中的每个点分数据的两位十六进制数值。The two-digit hexadecimal value of each dotted data in the multiple dotted data refers to the hexadecimal conversion of the digital fields separated by dots of the IP address respectively, to obtain the hexadecimal value in the multiple dotted data. The two-digit hexadecimal value of each dotted data.
串联是指去掉IP地址中间的点之后,将多个点分数据的多个两位十六进制数值从左到右进行顺序连接,得到IP地址的整数值。Concatenation means that after removing the dot in the middle of the IP address, multiple two-digit hexadecimal values of multiple dotted data are sequentially connected from left to right to obtain the integer value of the IP address.
通过采用上述预设规则,对目标IP地址进行转换,得到了无符号整数值形式的目标IP地址,从而可以通过数值的方法来对目标IP地址进行统计和分析。By adopting the above preset rules, the target IP address is converted to obtain a target IP address in the form of an unsigned integer value, so that the target IP address can be counted and analyzed by a numerical method.
S130、根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域;其中,起始地址整数值序列中的全部起始地址整数值和终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用预设规则转换得到的。S130. Determine the area to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence; wherein, all starting address integer values in the starting address integer value sequence All termination address integer values in the integer value sequence of the termination address and the termination address are obtained by converting the start address and the termination address of multiple IP address ranges that do not intersect with each other by using a preset rule.
起始地址和终止地址对应存在,由起始地址和终止地址构成了一个IP地址范围,而这个IP地址范围代表了一个区域。The start address and the end address exist correspondingly, and an IP address range is formed by the start address and the end address, and this IP address range represents an area.
互不交叉是指对于表示一个IP地址范围的起始地址和终止地址来说,起始地址和终止地址所在的网络地址(IP地址是由网络地址与主机地址两部分所组成)需要保持一致,也就是说,只有起始地址和终止地址所在的网络地址保持一致,才说明起始地址和终止地址是对应的,由此表示的IP地址范围才是正确的。网络地址是指互联网上的节点在网络中具有的逻辑地址,可对节点进行寻址,而主机地址是指IP地址右边部分用来标识主机本身的部分。同一IP地址范围的所有IP地址可以是分布在同一个区域的,例如属于同一个小区,同一个市区或者同一个省。Non-intersecting means that for the start address and end address of an IP address range, the network address where the start address and end address are located (the IP address is composed of two parts, the network address and the host address) needs to be consistent. That is to say, only if the network address where the start address and the end address are located are consistent, it means that the start address and the end address are corresponding, and the IP address range indicated by this is correct. The network address refers to the logical address that a node on the Internet has in the network, which can address the node, while the host address refers to the part on the right side of the IP address used to identify the host itself. All IP addresses in the same IP address range may be distributed in the same area, for example, belong to the same cell, the same urban area or the same province.
起始地址整数值序列是指有多个起始地址整数值进行排序得到的起始地址 整数值序列;终止地址整数值序列是指有多个终止地址整数值进行排序得到的终止地址整数值序列。起始地址整数值序列中的起始地址整数值与终止地址整数值序列中的终止地址整数值一一对应。The starting address integer value sequence refers to the starting address integer value sequence obtained by sorting multiple starting address integer values; the ending address integer value sequence refers to the ending address integer value sequence obtained by sorting multiple ending address integer values. . The starting address integer values in the starting address integer value sequence correspond one-to-one with the ending address integer values in the ending address integer value sequence.
可选地,起始地址整数值序列和终止地址整数值序列可在预先确定后,存储在内存中,待需要时就进行调用。Optionally, the starting address integer value sequence and the ending address integer value sequence may be pre-determined, stored in the memory, and called when needed.
本申请实施例,通过获取目标IP地址,对目标IP地址采用预设规则,转换成无符号整数值,以便于对目标IP地址进行查找,同时,预先确定的起始地址整数值序列和终止地址整数值序列分别是由多个起始地址整数值和多个终止地址整数值组成的序列,而多个起始地址整数值和多个终止地址整数值是由互不交叉的多个IP地址范围的起始地址和终止地址采用预设规则转换得到,保证了转换的一致性,以及互不交叉的多个IP地址范围保证了多个IP地址范围所在的区域不会发生重叠的情况,从而可以根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,准确地确定出目标IP地址的所属区域。通过采用本技术方案,可以达到简单、方便并准确的确定IP地址的所属区域的效果。In this embodiment of the present application, by obtaining the target IP address, the target IP address is converted into an unsigned integer value by adopting a preset rule, so as to facilitate searching for the target IP address. The integer value sequence is a sequence consisting of multiple starting address integer values and multiple ending address integer values respectively, and multiple starting address integer values and multiple ending address integer values are composed of multiple IP address ranges that do not intersect each other. The start address and end address of the IP address are converted using preset rules, which ensures the consistency of the conversion, and the multiple IP address ranges that do not intersect each other ensure that the areas where the multiple IP address ranges are located will not overlap, so that the According to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence, the area to which the target IP address belongs is accurately determined. By adopting the technical solution, the effect of simply, conveniently and accurately determining the area to which the IP address belongs can be achieved.
实施例二Embodiment 2
图2为本申请实施例二提供的IP地址所属区域的确定方法的流程图。本实施例是在上述实施例的基础上,对上述方案的说明。FIG. 2 is a flowchart of a method for determining a region to which an IP address belongs according to Embodiment 2 of the present application. This embodiment is based on the above-mentioned embodiment, and describes the above-mentioned scheme.
在操作“根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域”之前,增加操作“获取互不交叉的至少两个IP地址范围;其中,所述至少两个IP地址范围中的每个IP地址范围对应一个区域;确定每个IP地址范围的起始地址和终止地址;将所述起始地址和所述终止地址采用所述预设规则转换,得到所述每个IP地址范围的起始地址整数值和终止地址整数值;对所述至少两个IP地址范围的起始地址整数值按照从小到大的顺序进行排序,得到起始地址整数值序列;并对所述至少两个IP地址范围的终止地址整数值按照从小到大的顺序进行排序,得到终止地址整数值序列”,以完善起始地址整数值序列和终止地址整数值序列确定的过程。Before the operation "According to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and end address integer value sequence, determine the area to which the target IP address belongs", add the operation "Acquiring at least two non-intersecting IP address range; wherein, each IP address range in the at least two IP address ranges corresponds to an area; determine the start address and end address of each IP address range; combine the start address and the end address Using the preset rule conversion, the starting address integer value and the ending address integer value of each IP address range are obtained; the starting address integer values of the at least two IP address ranges are in ascending order. Sort to obtain a sequence of integer values of starting addresses; and sort the integer values of ending addresses of the at least two IP address ranges in ascending order to obtain a sequence of integer values of ending addresses", so as to improve the sequence of integer values of starting addresses. and terminates the process of address integer value sequence determination.
在操作“得到起始地址整数值序列和终止地址整数值序列”之后,增加操作“将所述起始地址整数值序列装载到连续的内存中,并将所述终止地址整数值序列装载到连续的内存中”,以完善对起始地址整数值序列和终止地址整数值序列的存储操作。After the operation "get the starting address integer value sequence and the ending address integer value sequence", add the operation "load the starting address integer value sequence into contiguous memory, and load the ending address integer value sequence into contiguous memory "in memory" to perfect the storage operation for the sequence of integer values at the starting address and the sequence of integer values at the ending address.
与上述实施例相同或相应的术语的解释在此不再赘述。The explanations of terms that are the same as or corresponding to the above-mentioned embodiments are not repeated here.
参见图2,本实施例提供的一种IP地址所属区域的确定方法包括如下步骤。Referring to FIG. 2 , a method for determining an area to which an IP address belongs provided by this embodiment includes the following steps.
S210、获取目标IP地址。S210. Obtain the target IP address.
S220、对目标IP地址采用预设规则,转换成无符号整数值。S220. Adopt a preset rule to convert the target IP address into an unsigned integer value.
S230、获取互不交叉的至少两个IP地址范围;其中,每个IP地址范围对应一个区域。S230. Acquire at least two IP address ranges that do not intersect with each other; wherein, each IP address range corresponds to an area.
互不交叉的至少两个IP地址范围保证了至少两个IP地址范围所在的区域不会发生重叠的情况。The at least two IP address ranges that do not overlap each other ensure that the areas where the at least two IP address ranges are located will not overlap.
可选地,在获取互不交叉的至少两个IP地址范围之前,还包括:对所述至少两个IP地址范围是否存在交叉进行检测;若检测到所述至少两个IP地址范围存在交叉,则生成存在交叉错误的提示信息,以供工作人员对交叉错误进行修改。Optionally, before acquiring at least two IP address ranges that do not intersect each other, the method further includes: detecting whether the at least two IP address ranges overlap; if it is detected that the at least two IP address ranges overlap, Then, a prompt message that there is a crossover error is generated for the staff to modify the crossover error.
提示信息包括示出存在交叉的起始地址信息和终止地址信息,以便于工作人员对交叉错误进行针对性修改。The prompt information includes the starting address information and the ending address information indicating that there is a crossover, so that the staff can make targeted corrections to the crossover error.
通过对IP地址范围是否存在交叉进行检测,保证了IP地址范围的准确性,并且在检测到两个IP地址存在交叉时,告警给工作人员,以便进行及时修正。By detecting whether the IP address ranges intersect, the accuracy of the IP address ranges is ensured, and when two IP addresses are detected intersecting, an alarm is sent to the staff for timely correction.
S240、确定每个IP地址范围的起始地址和终止地址。S240. Determine the start address and the end address of each IP address range.
在获取互不交叉的至少两个IP地址范围之后,由于每个IP地址范围都有一个起始地址和终止地址,因此,基于上述多个IP地址范围,可确定多个起始地址和终止地址。After acquiring at least two non-intersecting IP address ranges, since each IP address range has a starting address and an ending address, based on the above multiple IP address ranges, multiple starting addresses and ending addresses can be determined .
S250、将每个IP地址范围的起始地址和终止地址采用预设规则进行转换,得到所述每个IP地址范围的起始地址整数值和终止地址整数值。S250. Convert the starting address and ending address of each IP address range by using a preset rule, to obtain the integer value of the starting address and the integer value of the ending address of each IP address range.
对起始地址的点分数据进行十六进制转换,得到多个点分数据中每个点分数据的两位十六进制数值;对多个点分数据的两位十六进制数值串联得到起始地址的整数值;对终止地址的点分数据进行十六进制转换,得到多个点分数据中每个点分数据的两位十六进制数值;对多个点分数据的两位十六进制数值串联得到终止地址的整数值。Perform hexadecimal conversion on the dotted data of the starting address to obtain the two-digit hexadecimal value of each dotted data in the multiple dotted data; for the two-digit hexadecimal value of the multiple dotted data The integer value of the starting address is obtained by concatenating in series; the hexadecimal conversion is performed on the dotted data of the end address to obtain the two-digit hexadecimal value of each dotted data in the multiple dotted data; The concatenation of the two-digit hexadecimal value gives the integer value of the terminating address.
预先确定的起始地址整数值和终止地址整数值,与目标IP地址进行无符号整数值转换的规则相同,保证了转换的一致性,有利于对目标IP地址进行准确查找。The predetermined integer value of the starting address and the integer value of the ending address are the same as the rules for unsigned integer value conversion of the target IP address, which ensures the consistency of the conversion and is conducive to the accurate search of the target IP address.
S260、对所述至少两个IP地址范围的起始地址整数值按照从小到大的顺序进行排序,得到起始地址整数值序列;并对所述至少两个IP地址范围的终止地址整数值按照从小到大的顺序进行排序,得到终止地址整数值序列。S260. Sort the integer values of the starting addresses of the at least two IP address ranges in ascending order to obtain a sequence of integer values of the starting addresses; and sort the integer values of the ending addresses of the at least two IP address ranges according to the following order: Sort from small to large to get a sequence of terminating address integer values.
通过多个对起始地址整数值和多个终止地址整数值进行升序排列得到起始地址整数值序列和起始地址整数值序列,有利于后续对目标IP地址表示的无符号整数值进行查找。The starting address integer value sequence and the starting address integer value sequence are obtained by arranging multiple starting address integer values and multiple ending address integer values in ascending order, which facilitates subsequent searching of the unsigned integer value represented by the target IP address.
S270、将起始地址整数值序列装载到连续的内存中,并将终止地址整数值序列装载到连续的内存中。S270: Load the sequence of integer values of the starting address into the continuous memory, and load the sequence of integer values of the ending address into the continuous memory.
内存是指用来存储起始地址整数值序列和终止地址整数值序列的持久性内存。该内存可以是移动硬盘或光盘等,本申请实施例对此不做限定。Memory refers to persistent memory used to store a sequence of integer values for a starting address and a sequence of integer values for an ending address. The memory may be a mobile hard disk, an optical disk, or the like, which is not limited in this embodiment of the present application.
本申请实施例对上述S230~S270和S210~S220的执行顺序不做限定,S210~S220可以先于S230~270执行,也可以在执行完S230~S270之后,再执行S210~S220。This embodiment of the present application does not limit the execution order of the foregoing S230 to S270 and S210 to S220. S210 to S220 may be executed before S230 to 270, or S210 to S220 may be executed after S230 to S270 is executed.
在一个可选实施例中,假设起始地址整数值序列长度为1,对应的,终止地址整数值序列的长度也为l,将起始地址整数值序列和终止地址整数值序列用数组进行保存,得到的无符号整数形式的升序排列的起始地址数组记为As,得到的无号整数形式的升序排列的终止地址数组记为Ae,数组As和Ae的数组长度均为l。In an optional embodiment, it is assumed that the length of the starting address integer value sequence is 1, and correspondingly, the length of the ending address integer value sequence is also 1, and the starting address integer value sequence and the ending address integer value sequence are stored in an array , the obtained starting address array in the form of unsigned integers in ascending order is denoted as As, the obtained array of ending addresses in ascending order in the form of unsigned integers is denoted as Ae, and the array lengths of the arrays As and Ae are both l.
可选地,通过内存镜像的方式将起始地址数组和终止地址数组存储在计算机的内存中。待进行读取起始地址数组和终止地址数组时,就可以将起始地址数组和终止地址数组当作已全部被载入计算机内存一样的去访问。Optionally, the starting address array and the ending address array are stored in the memory of the computer by means of memory mirroring. When the starting address array and the ending address array are to be read, the starting address array and the ending address array can be accessed as if they have all been loaded into the computer memory.
创建一个二进制空文件Fs,将n(数组的长度)按无符号整数内存映像方式逐字节添加到文件Fs中去,然后将As也按内存映像的方式逐字节添加到文件Fs中去;创建一个二进制空文件Fe,将n按无符号整数内存映像方式逐字节添加到文件Fe中去,然后将Ae也按内存映像的方式逐字节添加到文件Fe中去。Create a binary empty file Fs, add n (the length of the array) to the file Fs byte by byte according to the unsigned integer memory mapping method, and then add As to the file Fs byte by byte according to the memory mapping method; Create a binary empty file Fe, add n to the file Fe byte by byte according to the unsigned integer memory mapping method, and then add Ae to the file Fe byte by byte according to the memory mapping method.
通过内存镜像的方式将起始地址数组和终止地址数组存储在计算机的内存中,可以达到简单、快速的对起始地址数组和终止地址数组进行访问的效果。By storing the starting address array and the ending address array in the memory of the computer by means of memory mirroring, the effect of accessing the starting address array and the ending address array simply and quickly can be achieved.
S280、根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域;其中,起始地址整数值序列中的全部起始地址整数值和终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用预设规则转换得到的。S280. Determine the region to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence; wherein, all starting address integer values in the starting address integer value sequence All termination address integer values in the integer value sequence of the termination address and the termination address are obtained by converting the start address and the termination address of multiple IP address ranges that do not intersect with each other by using a preset rule.
本实施例中,在根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域之前,需要从内存中读取预先确定的起始地址整数值序列和终止地址整数值序列。从内存中读取预先确定的起始地址整数值序列和终止地址整数值序列的方式可参照如下方式。In this embodiment, before the region to which the target IP address belongs is determined according to the relationship between the unsigned integer value and the predetermined starting address integer value sequence and the ending address integer value sequence, the predetermined starting address needs to be read from the memory. A sequence of address integer values and a sequence of terminating address integer values. The manner of reading the predetermined starting address integer value sequence and the ending address integer value sequence from the memory may refer to the following manner.
定义一个用于存储整数值序列的结构体(采用C/C++语言),代码如下:Define a structure (in C/C++ language) for storing a sequence of integer values, the code is as follows:
struct kb_addr{struct kb_addr{
uint_t count;//uint_t表示无符号的整数类型,count表示地址个数uint_t count; //uint_t represents an unsigned integer type, and count represents the number of addresses
uint_t*saddrs;//saddrs表示起始地址首地址uint_t*saddrs; //saddrs indicates the first address of the starting address
};};
uint_t*是指向无符号整数的指针类型。uint_t* is a pointer to unsigned integer type.
在需要将起始地址数组装载进内存时,创建一个用来表示起始地址数组的结构体变量:struct kb_addr mykaddr_s。对Fs中保存的n进行读取,并将它赋值给mykaddr_s.count;接着分配一块连续的内存块Bs以容纳n个uint_t数,该块内存的首地址保存到mykaddr_s.saddrs中;然后将Fs中n之后的内容逐字节对拷到Bs中。创建一个用来表示终止地址数组的结构体变量:struct kb_addr mykaddr_e;对Fe中保存的n进行读取,并将它赋值给mykaddr_e.count;接着分配一块连续的内存块Be以容纳n个uint_t数,该块内存的首地址保存到mykaddr_e.saddrs中;然后将Fe中n之后的内容逐字节对拷到Be中。至此,查询时所需要的信息已经准备好了。至此,查找时所需要的起始地址整数值序列和终止地址整数值序列已读取完成。When you need to load the starting address array into memory, create a structure variable to represent the starting address array: struct kb_addr mykaddr_s. Read the n stored in Fs and assign it to mykaddr_s.count; then allocate a continuous memory block Bs to accommodate n uint_t numbers, and save the first address of this block of memory to mykaddr_s.saddrs; then Fs The content after n is copied to Bs byte by byte. Create a structure variable used to represent the termination address array: struct kb_addr mykaddr_e; read the n stored in Fe and assign it to mykaddr_e.count; then allocate a continuous memory block Be to accommodate n uint_t numbers , the first address of this block of memory is stored in mykaddr_e.saddrs; then the content after n in Fe is copied byte by byte to Be. At this point, the information required for the query has been prepared. So far, the starting address integer value sequence and the ending address integer value sequence required for searching have been read.
本申请实施例在上述实施例的基础上,将起始地址整数值序列和终止地址整数值序列的确定过程进行了描述,首先针对获取到的互不交叉的多个IP地址范围,来确定每个IP地址范围的起始地址和终止地址,并根据预设规则对每个IP地址范围的起始地址和终止地址进行转换,得到每个IP地址范围的起始地址整数值和终止地址整数值,然后将互不交叉的多个IP地址范围的起始地址整数值和终止地址整数值进行升序排列得到起始地址整数值序列和起始地址整数值序列,最后根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定了目标IP地址的所属区域;其中,预先确定的起始地址整数值序列和终止地址整数值序列为确定目标IP地址的所属区域提供了数据库支撑;并且将预先确定的起始地址整数值序列和终止地址整数值序列装载在连续的内存中,可以很方便、快捷地进行调用,达到了简单、方便并准确的确定IP地址的所属区域的效果。On the basis of the above-mentioned embodiments, the embodiments of the present application describe the process of determining the integer value sequence of the starting address and the integer value sequence of the ending address. The starting address and ending address of each IP address range are converted according to preset rules to obtain the starting address and ending address integer value of each IP address range. , and then arrange the starting address integer values and ending address integer values of multiple non-intersecting IP address ranges in ascending order to obtain the starting address integer value sequence and the starting address integer value sequence. Finally, according to the unsigned integer value and the predetermined value The relationship between the starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, the predetermined starting address integer value sequence and the ending address integer value sequence determine the area to which the target IP address belongs. Provides database support; and loads the predetermined starting address integer value sequence and ending address integer value sequence in the continuous memory, which can be called very conveniently and quickly, and achieves a simple, convenient and accurate IP address determination. The effect of the region it belongs to.
实施例三Embodiment 3
图3为本申请实施例三提供的IP地址所属区域的确定方法的流程图。本实施例是在上述实施例的基础上,对上述方案的说明。FIG. 3 is a flowchart of a method for determining an area to which an IP address belongs according to Embodiment 3 of the present application. This embodiment is based on the above-mentioned embodiment, and describes the above-mentioned scheme.
将操作“根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域”,描述为“采用二分法确定起始地址整数值序列中小于或者等于所述无符号整数值的待识别起始地址 整数值;确定与所述待识别起始地址整数值对应的待识别终止地址整数值;若所述无符号整数值在所述待识别起始地址整数值和所述待识别终止地址整数值之间,则确定目标IP地址的所属区域与所述待识别起始地址整数值的IP地址范围的区域相同”,以完善对目标IP地址的所属区域的确定过程。The operation "determining the region to which the target IP address belongs according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the integer value of the ending address" is described as "using the method of dichotomy to determine the integer value of the starting address. The integer value of the starting address to be identified that is less than or equal to the unsigned integer value in the sequence; determine the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified; if the unsigned integer value is in the Between the integer value of the starting address to be identified and the integer value of the ending address to be identified, it is determined that the area to which the target IP address belongs is the same as the area of the IP address range of the integer value of the starting address to be identified. The process of determining the area to which the IP address belongs.
与上述实施例相同或相应的术语的解释在此不再赘述。The explanations of terms that are the same as or corresponding to the above-mentioned embodiments are not repeated here.
参见图3,本实施例提供的一种IP地址所属区域的确定方法包括如下步骤。Referring to FIG. 3 , a method for determining an area to which an IP address belongs provided by this embodiment includes the following steps.
S310、获取目标IP地址。S310. Obtain the target IP address.
S320、对目标IP地址采用预设规则,转换成无符号整数值。S320. Adopt a preset rule to convert the target IP address into an unsigned integer value.
S330、采用二分法确定起始地址整数值序列中小于或者等于无符号整数值的待识别起始地址整数值。S330. Use a dichotomy method to determine the integer value of the starting address to be identified that is smaller than or equal to the unsigned integer value in the starting address integer value sequence.
二分法是指一种折半查找方法,能快速地对待查询的数据进行查找。Dichotomy refers to a method of halving search, which can quickly search the data to be queried.
采用二分法确定起始地址整数值序列中小于或者等于无符号整数值的待识别起始地址整数值是指在起始地址整数值序列中,找出与无符号整数值最接近的起始地址整数值,并且该起始地址整数值需要小于无符号整数值。也就是说,需要在起始地址整数值序列中确定出的待识别起始地址整数值是小于等于无符号整数值的最大的那一项。Using dichotomy to determine the starting address integer value to be identified that is less than or equal to the unsigned integer value in the starting address integer value sequence refers to finding the starting address closest to the unsigned integer value in the starting address integer value sequence. Integer value, and the starting address integer value needs to be less than the unsigned integer value. That is, the integer value of the starting address to be identified that needs to be determined in the integer value sequence of the starting address is the largest item less than or equal to the unsigned integer value.
在采用二分法对无符号整数值进行查找的过程中,针对按升序排列的起始地址整数值序列,将起始地址整数值序列中间位置记录的地址整数值与无符号整数值比较,如果起始地址整数值序列中间位置记录的地址整数值与无符号整数值两者相等,则无符号整数值查找成功;如果起始地址整数值序列中间位置记录的地址整数值与无符号整数值不相等,继续将起始地址整数值序列进行切分查找;并利用中间位置记录的地址整数值将起始地址整数值序列分成前、后两个子起始地址整数值序列,如果中间位置记录的地址整数值小于无符号整数值,则查找后一子起始地址整数值序列,如果中间位置记录的地址整数值大于无符号整数值,则查找前一子起始地址整数值序列。重复上述过程,直到找到满足条件的地址整数值,使待识别起始地址整数值查找成功。In the process of searching for unsigned integer values using the dichotomy method, for the starting address integer value sequence arranged in ascending order, compare the address integer value recorded at the middle position of the starting address integer value sequence with the unsigned integer value. If the integer value of the address recorded in the middle of the integer value sequence of the starting address is equal to the unsigned integer value, the unsigned integer value search is successful; if the integer value of the address recorded at the middle position of the integer value sequence of the starting address is not equal to the unsigned integer value , continue to split the starting address integer value sequence; and use the address integer value recorded in the middle position to divide the starting address integer value sequence into two sub-starting address integer value sequences before and after. If the address integer value recorded at the middle position If the value is less than the unsigned integer value, search for the integer value sequence of the starting address of the next child. If the integer value of the address recorded in the middle position is greater than the unsigned integer value, search for the integer value sequence of the starting address of the previous child. The above process is repeated until an address integer value that satisfies the condition is found, so that the search for the integer value of the starting address to be identified is successful.
S340、确定与待识别起始地址整数值对应的待识别终止地址整数值。S340. Determine the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified.
待识别终止地址整数值与待识别起始地址整数值一一对应。由待识别起始地址整数值在起始地址整数值序列中的位置索引,可直接在终止地址整数值序列相同的位置索引处,确定待识别终止地址整数值。The integer value of the ending address to be identified corresponds to the integer value of the starting address to be identified. From the position index of the integer value of the starting address to be identified in the integer value sequence of the starting address, the integer value of the ending address to be identified can be directly determined at the same position index of the integer value sequence of the ending address.
S350、若无符号整数值在待识别起始地址整数值和待识别终止地址整数值之间,则确定目标IP地址的所属区域与待识别起始地址整数值和待识别终止地 址整数值之间的IP地址范围的区域相同。S350. If the unsigned integer value is between the integer value of the starting address to be identified and the integer value of the ending address to be identified, determine the region to which the target IP address belongs and the integer value of the starting address to be identified and the integer value of the ending address to be identified. The IP address range is the same as the zone.
在待识别起始地址整数值和待识别终止地址整数值之间的无符号整数值,拥有与待识别起始地址整数值和待识别终止地址整数值相同的网络地址,也即由无符号整数值表示的目标IP地址与待识别起始地址整数值所表示的区域相同,目标IP地址所在的主机只是上述区域内众多主机中的一台主机。The unsigned integer value between the integer value of the starting address to be identified and the integer value of the ending address to be identified has the same network address as the integer value of the starting address to be identified and the integer value of the ending address to be identified, that is, an unsigned integer The target IP address represented by the value is the same as the area represented by the integer value of the starting address to be identified, and the host where the target IP address is located is only one of the many hosts in the above area.
可选地,若无符号整数值不在待识别起始地址整数值和待识别终止地址整数值之间,则确定目标IP地址的所属区域确定失败。Optionally, if the unsigned integer value is not between the integer value of the starting address to be identified and the integer value of the ending address to be identified, the determination of the area to which the target IP address belongs fails to be determined.
目标IP地址的所属区域确定失败可以是目标IP地址本身错误;或者,预先确定的起始地址整数值序列和终止地址整数值序列存在错误。在确定目标IP地址的所属区域确定失败后,可告警给工作人员,并对未成功进行区域确定的目标IP地址进行工作日志记录。The failure to determine the area to which the target IP address belongs may be due to an error in the target IP address itself; or, there is an error in the predetermined start address integer value sequence and end address integer value sequence. After the determination of the area to which the target IP address belongs fails to be determined, an alarm can be alerted to the staff, and a work log is recorded for the target IP address for which the area determination is unsuccessful.
可选地,工作人员定时查看工作日志,对目标IP地址进行查验,以及对预先确定的起始地址整数值序列和终止地址整数值序列进行查验,以确定错误原因,并进行相应调整。Optionally, the staff periodically checks the work log, checks the target IP address, and checks the predetermined start address integer value sequence and end address integer value sequence to determine the cause of the error and make corresponding adjustments.
本申请实施例在上述实施例的基础上,通过对待进行所属区域确定的目标IP地址,进行转换得到无符号整数值,根据无符号整数值与预先确定的起始地址整数值序列的关系,由二分查找方法确定了小于或者等于无符号整数值的待识别起始地址整数值,根据起始地址整数值序列和终止地址整数值序列的对应关系,由待识别起始地址整数值确定了待识别终止地址整数值,根据待识别起始地址整数值和待识别终止地址整数值形成的IP地址范围,确定无符号整数值是否落在上述IP地址范围内,若在确定落在上述IP地址范围内,则目标IP地址所属区域就在上述IP地址范围内;通过上述方案,达到了简单、方便并准确的确定IP地址的所属区域的效果。On the basis of the above-mentioned embodiments, the embodiment of the present application obtains an unsigned integer value by converting the target IP address to be determined in the region to which it belongs. According to the relationship between the unsigned integer value and the predetermined starting address integer value sequence, the The binary search method determines the integer value of the starting address to be identified that is less than or equal to the unsigned integer value. The integer value of the termination address, according to the IP address range formed by the integer value of the starting address to be identified and the integer value of the ending address to be identified, to determine whether the unsigned integer value falls within the above IP address range, and if it is determined to fall within the above IP address range , the area to which the target IP address belongs is within the above IP address range; through the above solution, the effect of simply, conveniently and accurately determining the area to which the IP address belongs is achieved.
实施例四Embodiment 4
图4是本申请实施例四提供的一种IP地址所属区域的确定装置的结构示意图。参见图4,本申请实施例提供的一种IP地址所属区域的确定装置,该装置包括:目标地址获取模块410、转换模块420和目标区域确定模块430。FIG. 4 is a schematic structural diagram of an apparatus for determining an area to which an IP address belongs according to Embodiment 4 of the present application. Referring to FIG. 4 , an apparatus for determining an area to which an IP address belongs provided by an embodiment of the present application includes: a target address acquisition module 410 , a conversion module 420 , and a target area determination module 430 .
目标地址获取模块410,设置为获取目标IP地址;转换模块420,设置为对所述目标IP地址采用预设规则,转换成无符号整数值;目标区域确定模块430,设置为根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域;其中,所述起始地址整数值序列中的全部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换 得到的。The target address obtaining module 410 is configured to obtain the target IP address; the conversion module 420 is configured to adopt a preset rule to convert the target IP address into an unsigned integer value; the target area determination module 430 is configured to The relationship between the integer value and the predetermined starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; wherein, all the starting address integer values in the starting address integer value sequence and the All the termination address integer values in the termination address integer value sequence are obtained by converting the start addresses and termination addresses of multiple IP address ranges that do not intersect with each other by using the preset rule.
本申请实施例通过获取目标IP地址,对目标IP地址采用预设规则,转换成无符号整数值,以便于对目标IP地址进行查找,同时,预先确定的起始地址整数值序列和终止地址整数值序列分别是由多个起始地址整数值和终止地址整数值组成的序列,而多个起始地址整数值和多个终止地址整数值是由互不交叉的多个IP地址范围的起始地址和终止地址采用预设规则转换得到,保证了转换的一致性,以及互不交叉的多个IP地址范围保证了多个IP地址范围所在的区域不会发生重叠的情况,从而可以根据无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,准确地确定出目标IP地址的所属区域,达到了简单、方便并准确的确定IP地址的所属区域的效果。The embodiment of the present application obtains the target IP address, adopts preset rules for the target IP address, and converts the target IP address into an unsigned integer value, so as to facilitate the search for the target IP address. At the same time, the predetermined starting address integer value sequence and the ending address integer The value sequence is a sequence consisting of multiple starting address integer values and multiple ending address integer values, respectively, and multiple starting address integer values and multiple ending address integer values are the starting addresses of multiple non-intersecting IP address ranges. The address and the termination address are converted by preset rules, which ensures the consistency of the conversion, and the multiple IP address ranges that do not cross each other ensure that the areas where the multiple IP address ranges are located will not overlap. The relationship between the integer value and the predetermined starting address integer value sequence and ending address integer value sequence accurately determines the area to which the target IP address belongs, and achieves the effect of simply, conveniently and accurately determining the area to which the IP address belongs.
所述预设规则包括:对IP地址的多个点分数据中的每个点分数据进行十六进制转换,得到每个点分数据的两位十六进制数值;对多个点分数据的两位十六进制数值进行串联得到IP地址的整数值。The preset rules include: performing hexadecimal conversion on each point data in the multiple point data of the IP address to obtain a two-digit hexadecimal value of each point data; The two hexadecimal values of the data are concatenated to obtain the integer value of the IP address.
目标区域确定模块,包括:地址获取单元,设置为获取互不交叉的至少两个IP地址范围;其中,每个IP地址范围对应一个区域;地址确定单元,设置为确定每个IP地址范围的起始地址和终止地址;地址转换单元,设置为将所述起始地址和所述终止地址采用所述预设规则进行转换,得到所述每个IP地址范围的起始地址整数值和终止地址整数值;地址排序单元,设置为对所述至少两个IP地址范围的起始地址整数值按照从小到大的顺序进行排序,得到起始地址整数值序列;并对所述至少两个IP地址范围的终止地址整数值按照从小到大的顺序进行排序,得到终止地址整数值序列。The target area determination module includes: an address acquisition unit, configured to acquire at least two IP address ranges that do not intersect with each other; wherein, each IP address range corresponds to an area; and an address determination unit is configured to determine the starting point of each IP address range. starting address and ending address; an address conversion unit, configured to convert the starting address and the ending address using the preset rule, to obtain the starting address integer value and ending address integer value of each IP address range an address sorting unit, configured to sort the starting address integer values of the at least two IP address ranges in ascending order to obtain a sequence of starting address integer values; The termination address integer values of are sorted in ascending order to obtain the termination address integer value sequence.
目标区域确定模块,还包括:装载单元,设置为在得到起始地址整数值序列和终止地址整数值序列之后,将所述起始地址整数值序列装载到连续的内存中,并将所述终止地址整数值序列装载到连续的内存中。The target area determination module further includes: a loading unit, configured to load the starting address integer value sequence into a continuous memory after obtaining the starting address integer value sequence and the ending address integer value sequence, and load the terminating address integer value sequence into a continuous memory. A sequence of address integer values is loaded into contiguous memory.
目标区域确定模块,还包括:检测单元,设置为在获取互不交叉的至少两个IP地址范围之前,对所述至少两个IP地址范围是否存在交叉进行检测;提示信息生成单元,设置为若检测到所述至少两个IP地址范围存在交叉,则生成存在交叉错误的提示信息,以供工作人员对所述交叉错误进行修改。The target area determination module further includes: a detection unit, configured to detect whether the at least two IP address ranges intersect each other before acquiring at least two IP address ranges that do not intersect with each other; a prompt information generation unit, set to if If it is detected that the at least two IP address ranges overlap, prompt information that there is an overlap error is generated, so that the staff can revise the overlap error.
目标区域确定模块,还包括:起始地址识别单元,设置为采用二分法确定起始地址整数值序列中小于或者等于所述无符号整数值的待识别起始地址整数值;终止地址识别单元,设置为确定与所述待识别起始地址整数值对应的待识别终止地址整数值;目标区域确定单元,设置为若所述无符号整数值在所述待识别起始地址整数值和所述待识别终止地址整数值之间,则确定目标IP地址的所属区域与所述待识别起始地址整数值的IP地址范围的区域相同。The target area determination module further includes: a start address identification unit, configured to use a binary method to determine the start address integer value to be identified that is less than or equal to the unsigned integer value in the start address integer value sequence; the end address identification unit, be set to determine the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified; the target area determination unit is set to if the unsigned integer value is between the integer value of the starting address to be identified and the integer value of the starting address to be identified If the integer value of the end address is identified, it is determined that the area to which the target IP address belongs is the same as the area of the IP address range of the integer value of the start address to be identified.
目标区域确定单元,还设置为若所述无符号整数值不在所述待识别起始地址整数值和所述待识别终止地址整数值之间,则确定目标IP地址的所属区域确定失败。The target area determination unit is further configured to fail to determine the area to which the target IP address belongs if the unsigned integer value is not between the integer value of the starting address to be identified and the integer value of the ending address to be identified.
本申请实施例所提供的IP地址所属区域的确定装置可执行本申请任意实施例所提供的IP地址所属区域的确定方法,具备执行方法相应的功能模块。The apparatus for determining the area to which the IP address belongs provided by the embodiment of the present application can execute the method for determining the area to which the IP address belongs provided by any embodiment of the present application, and has functional modules corresponding to the execution method.
实施例五Embodiment 5
图5为本申请实施例五提供的一种电子设备的结构示意图。如图5所示,该设备包括处理器510、存储器520、输入装置530和输出装置540。FIG. 5 is a schematic structural diagram of an electronic device according to Embodiment 5 of the present application. As shown in FIG. 5 , the apparatus includes a processor 510 , a memory 520 , an input device 530 and an output device 540 .
设备中处理器510的数量可以是一个或多个,图5中以一个处理器510为例;设备中的处理器510、存储器520、输入装置530和输出装置540可以通过总线或其他方式连接,图5中以通过总线连接为例。The number of processors 510 in the device can be one or more, and one processor 510 is taken as an example in FIG. 5; the processor 510, the memory 520, the input device 530 and the output device 540 in the device can be connected through a bus or other means, In FIG. 5, the connection through the bus is taken as an example.
输入装置530,设置为接收目标IP地址。The input device 530 is configured to receive the target IP address.
输出装置540,设置为输出目标IP地址的所属区域。The output device 540 is configured to output the area to which the target IP address belongs.
处理器510可以根据输入装置530输入的目标IP地址,对所述目标IP地址采用预设规则,将目标IP地址转换成无符号整数值;还可以根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域;还可以向输出装置540传输目标IP地址的所属区域。The processor 510 can convert the target IP address into an unsigned integer value according to the target IP address input by the input device 530 using a preset rule for the target IP address; it can also be based on the unsigned integer value and a predetermined starting point. The relationship between the starting address integer value sequence and the ending address integer value sequence determines the area to which the target IP address belongs; the area to which the target IP address belongs may also be transmitted to the output device 540 .
存储器520作为一种计算机可读存储介质,可设置为存储软件程序、计算机可执行程序以及模块,如本申请实施例中的IP地址所属区域的确定方法对应的程序指令/模块(例如,IP地址所属区域的确定装置中的目标地址获取模块410、转换模块420和目标区域确定模块430)。处理器510通过运行存储在存储器520中的软件程序、指令以及模块,从而执行设备的多种功能应用以及数据处理,即实现上述的IP地址所属区域的确定方法。As a computer-readable storage medium, the memory 520 can be configured to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the method for determining the region to which the IP address belongs in the embodiments of the present application (for example, the IP address). The target address acquisition module 410, the conversion module 420 and the target area determination module 430 in the device for determining the belonging area). The processor 510 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 520 , that is, to implement the above-mentioned method for determining the area to which the IP address belongs.
存储器520可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序;存储数据区可存储根据终端的使用所创建的数据等(如上述实施例中的目标IP地址、起始地址整数值序列和终止地址整数值序列等)。此外,存储器520可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。在一些实例中,存储器520还可包括相对于处理器510远程设置的存储器,这些远程存储器可以通过网络连接至设备。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory 520 may mainly include a stored program area and a stored data area, wherein the stored program area may store an operating system, an application program required for at least one function; the stored data area may store data created according to the use of the terminal, etc. In the example, the destination IP address, the starting address integer value sequence and the ending address integer value sequence, etc.). Additionally, memory 520 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, memory 520 may also include memory located remotely from processor 510, which may be connected to the device through a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
输入装置530可设置为接收输入的数字或字符信息,以及产生与设备的用户设置以及功能控制有关的键信号输入。输出装置540可包括显示屏等显示设 备。The input device 530 may be configured to receive input numerical or character information, and to generate key signal input related to user settings and function control of the device. The output device 540 may include a display device such as a display screen.
实施例六Embodiment 6
本申请实施例六还提供一种包含计算机可执行指令的存储介质,所述计算机可执行指令在由计算机处理器执行时用于执行一种IP地址所属区域的确定方法,该方法包括:获取目标IP地址;对所述目标IP地址采用预设规则,转换成无符号整数值;根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定目标IP地址的所属区域;其中,所述起始地址整数值序列中的全部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换得到的。Embodiment 6 of the present application further provides a storage medium containing computer-executable instructions, where the computer-executable instructions are used to execute a method for determining a region to which an IP address belongs when executed by a computer processor, the method comprising: obtaining a target IP address; use preset rules to convert the target IP address into an unsigned integer value; determine the target IP according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the sequence of integer values of the ending address The region to which the address belongs; wherein, all the starting address integer values in the starting address integer value sequence and all ending address integer values in the ending address integer value sequence are the starting points of multiple non-intersecting IP address ranges. The start address and end address are obtained by converting using the preset rules.
通过以上关于实施方式的描述,所属领域的技术人员可以了解到,本申请可借助软件及通用硬件来实现,当然也可以通过硬件实现。基于这样的理解,本申请的技术方案可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如计算机的软盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、闪存(FLASH)、硬盘或光盘等,包括多个指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请多个个实施例所述的方法。From the above description of the embodiments, those skilled in the art can understand that the present application can be implemented by means of software and general hardware, and certainly can also be implemented by hardware. Based on this understanding, the technical solution of the present application 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 a floppy disk of a computer, a read-only memory (Read-Only Memory, ROM), Random Access Memory (Random Access Memory, RAM), flash memory (FLASH), hard disk or optical disk, etc., including multiple instructions to make a computer device (which may be a personal computer, server, or network device, etc.) The method described in each embodiment.
值得注意的是,上述IP地址所属区域的确定装置的实施例中,所包括的多个单元和模块只是按照功能逻辑进行划分的,但并不局限于上述的划分,只要能够实现相应的功能即可;另外,多个功能单元的名称也只是为了便于相互区分,并不用于限制本申请的保护范围。It is worth noting that, in the above-mentioned embodiment of the apparatus for determining the region to which the IP address belongs, the multiple units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be realized, that is, Yes; in addition, the names of multiple functional units are only for the convenience of distinguishing from each other, and are not used to limit the protection scope of the present application.

Claims (10)

  1. 一种国际互连协议IP地址所属区域的确定方法,包括:A method for determining the area to which an IP address of an international interconnection agreement belongs, comprising:
    获取目标IP地址;Get the target IP address;
    对所述目标IP地址采用预设规则,转换成无符号整数值;The target IP address is converted into an unsigned integer value by adopting a preset rule;
    根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定所述目标IP地址的所属区域;其中,所述起始地址整数值序列中的全部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换得到的。The region to which the target IP address belongs is determined according to the relationship between the unsigned integer value and the predetermined sequence of integer values of the starting address and the ending address; The integer value of the starting address and all the integer values of the ending address in the sequence of integer values of the ending address are obtained by converting the starting address and the ending address of multiple IP address ranges that do not intersect with each other by using the preset rule.
  2. 根据权利要求1所述的方法,其中,所述起始地址整数值序列和所述终止地址整数值序列的确定过程,包括:The method according to claim 1, wherein the determining process of the starting address integer value sequence and the ending address integer value sequence comprises:
    获取互不交叉的至少两个IP地址范围;其中,每个IP地址范围对应一个区域;Obtain at least two IP address ranges that do not intersect with each other; wherein, each IP address range corresponds to an area;
    确定每个IP地址范围的起始地址和终止地址;Determine the start and end addresses of each IP address range;
    将所述起始地址和所述终止地址采用所述预设规则进行转换,得到所述每个IP地址范围的起始地址整数值和终止地址整数值;Converting the starting address and the ending address using the preset rule, to obtain the integer value of the starting address and the integer value of the ending address of each IP address range;
    对所述至少两个IP地址范围的起始地址整数值按照从小到大的顺序进行排序,得到所述起始地址整数值序列;并对所述至少两个IP地址范围的终止地址整数值按照从小到大的顺序进行排序,得到所述终止地址整数值序列。Sort the starting address integer values of the at least two IP address ranges in ascending order to obtain the starting address integer value sequence; and sort the ending address integer values of the at least two IP address ranges according to Sort from small to large to obtain the termination address integer value sequence.
  3. 根据权利要求2所述的方法,在得到所述起始地址整数值序列和所述终止地址整数值序列之后,还包括:The method according to claim 2, after obtaining the starting address integer value sequence and the ending address integer value sequence, further comprising:
    将所述起始地址整数值序列装载到连续的内存中,并将所述终止地址整数值序列装载到连续的内存中。The sequence of starting address integer values is loaded into contiguous memory, and the sequence of ending address integer values is loaded into contiguous memory.
  4. 根据权利要求2所述的方法,所述在获取互不交叉的至少两个IP地址范围之前,还包括:The method according to claim 2, before acquiring at least two non-intersecting IP address ranges, further comprising:
    对所述至少两个IP地址范围是否存在交叉进行检测;Detecting whether there is intersection between the at least two IP address ranges;
    响应于所述至少两个IP地址范围存在交叉的检测结果,生成存在交叉错误的提示信息,以供工作人员对所述交叉错误进行修改。In response to the detection result of the intersection of the at least two IP address ranges, prompt information that there is an intersection error is generated, so that the staff can revise the intersection error.
  5. 根据权利要求1所述的方法,其中,所述预设规则包括:The method of claim 1, wherein the preset rules include:
    对IP地址的多个点分数据中的每个点分数据进行十六进制转换,得到所述每个点分数据的两位十六进制数值;Carry out hexadecimal conversion to each point data in the multiple point data of the IP address, and obtain the two-digit hexadecimal value of each point point data;
    对所述多个点分数据的两位十六进制数值进行串联得到所述IP地址的整数 值。The integer value of the IP address is obtained by concatenating the two-digit hexadecimal values of the plurality of dotted data.
  6. 根据权利要求1所述的方法,其中,根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定所述目标IP地址的所属区域,包括:The method according to claim 1, wherein determining the region to which the target IP address belongs according to the relationship between the unsigned integer value and a predetermined sequence of integer values of the starting address and ending address, comprising:
    采用二分法确定所述起始地址整数值序列中小于或者等于所述无符号整数值的待识别起始地址整数值;Determine the starting address integer value to be identified that is less than or equal to the unsigned integer value in the starting address integer value sequence by using a dichotomy method;
    确定与所述待识别起始地址整数值对应的待识别终止地址整数值;determining the integer value of the ending address to be identified corresponding to the integer value of the starting address to be identified;
    在所述无符号整数值在所述待识别起始地址整数值和所述待识别终止地址整数值之间的情况下,确定所述目标IP地址的所属区域与所述待识别起始地址整数值的IP地址范围的区域相同。In the case that the unsigned integer value is between the integer value of the starting address to be identified and the integer value of the ending address to be identified, determine the region to which the target IP address belongs and the integer starting address to be identified The value is the same as the area of the IP address range.
  7. 根据权利要求6所述的方法,还包括:The method of claim 6, further comprising:
    在所述无符号整数值不在所述待识别起始地址整数值和所述待识别终止地址整数值之间的情况下,确定所述目标IP地址的所属区域确定失败。In the case that the unsigned integer value is not between the integer value of the starting address to be identified and the integer value of the ending address to be identified, it is determined that the determination of the area to which the target IP address belongs fails.
  8. 一种网际互连协议IP地址所属区域的确定装置,包括:A device for determining the area to which an Internet Protocol IP address belongs, comprising:
    目标地址获取模块,设置为获取目标IP地址;The target address obtaining module is set to obtain the target IP address;
    转换模块,设置为对所述目标IP地址采用预设规则,转换成无符号整数值;a conversion module, configured to adopt a preset rule for the target IP address and convert it into an unsigned integer value;
    目标区域确定模块,设置为根据所述无符号整数值与预先确定的起始地址整数值序列和终止地址整数值序列的关系,确定所述目标IP地址的所属区域;其中,所述起始地址整数值序列中的全部起始地址整数值和所述终止地址整数值序列中的全部终止地址整数值是互不交叉的多个IP地址范围的起始地址和终止地址采用所述预设规则转换得到的。The target area determination module is configured to determine the area to which the target IP address belongs according to the relationship between the unsigned integer value and a predetermined sequence of integer values of the starting address and the ending address; wherein, the starting address All starting address integer values in the integer value sequence and all ending address integer values in the ending address integer value sequence are the starting addresses and ending addresses of multiple IP address ranges that do not intersect with each other, and are converted using the preset rule owned.
  9. 一种电子设备,包括:An electronic device comprising:
    至少一个处理器;at least one processor;
    存储装置,设置为存储至少一个程序,storage means arranged to store at least one program,
    当所述至少一个程序被所述至少一个处理器执行,使得所述至少一个处理器实现如权利要求1-7中任一项所述的一种IP地址所属区域的确定方法。When the at least one program is executed by the at least one processor, the at least one processor implements the method for determining an area to which an IP address belongs according to any one of claims 1-7.
  10. 一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如权利要求1-7中任一项所述的一种IP地址所属区域的确定方法。A computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements the method for determining an area to which an IP address belongs according to any one of claims 1-7.
PCT/CN2021/119296 2020-12-28 2021-09-18 Method and apparatus for determining region to which ip address belongs, and electronic device and storage medium WO2022142499A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011581661.X 2020-12-28
CN202011581661.XA CN112671948A (en) 2020-12-28 2020-12-28 Method and device for determining IP address belonging area, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2022142499A1 true WO2022142499A1 (en) 2022-07-07

Family

ID=75411049

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/119296 WO2022142499A1 (en) 2020-12-28 2021-09-18 Method and apparatus for determining region to which ip address belongs, and electronic device and storage medium

Country Status (2)

Country Link
CN (1) CN112671948A (en)
WO (1) WO2022142499A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117278521A (en) * 2023-11-16 2023-12-22 烽台科技(北京)有限公司 Asset identification method and computer device

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112671948A (en) * 2020-12-28 2021-04-16 北京锐安科技有限公司 Method and device for determining IP address belonging area, electronic equipment and storage medium
CN114040033A (en) * 2021-10-26 2022-02-11 卓望数码技术(深圳)有限公司 IP address processing method, system and storage medium
CN114201520B (en) * 2021-12-09 2023-04-28 北京航星永志科技有限公司 Method and device for rapidly retrieving IP address and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106789137A (en) * 2015-11-19 2017-05-31 北京国双科技有限公司 The comparative approach and device of IP scopes
CN107682466A (en) * 2017-09-26 2018-02-09 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN108875006A (en) * 2018-06-15 2018-11-23 泰康保险集团股份有限公司 Determine method and device regional belonging to IP address
CN110266834A (en) * 2019-07-29 2019-09-20 中国工商银行股份有限公司 The regional lookup method and device of internet protocol-based address
US10740265B1 (en) * 2018-09-27 2020-08-11 Amazon Technologies, Inc. PCI-based bus system having peripheral device address translation based on base address register (BAR) index
CN112307138A (en) * 2019-07-30 2021-02-02 华扬联众数字技术股份有限公司 Storage and query method, system and medium of region information
CN112671948A (en) * 2020-12-28 2021-04-16 北京锐安科技有限公司 Method and device for determining IP address belonging area, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103617205A (en) * 2013-11-15 2014-03-05 北京奇虎科技有限公司 Method and device for identifying regional attribution information of IP (internet protocol) addresses

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106789137A (en) * 2015-11-19 2017-05-31 北京国双科技有限公司 The comparative approach and device of IP scopes
CN107682466A (en) * 2017-09-26 2018-02-09 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN108875006A (en) * 2018-06-15 2018-11-23 泰康保险集团股份有限公司 Determine method and device regional belonging to IP address
US10740265B1 (en) * 2018-09-27 2020-08-11 Amazon Technologies, Inc. PCI-based bus system having peripheral device address translation based on base address register (BAR) index
CN110266834A (en) * 2019-07-29 2019-09-20 中国工商银行股份有限公司 The regional lookup method and device of internet protocol-based address
CN112307138A (en) * 2019-07-30 2021-02-02 华扬联众数字技术股份有限公司 Storage and query method, system and medium of region information
CN112671948A (en) * 2020-12-28 2021-04-16 北京锐安科技有限公司 Method and device for determining IP address belonging area, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117278521A (en) * 2023-11-16 2023-12-22 烽台科技(北京)有限公司 Asset identification method and computer device
CN117278521B (en) * 2023-11-16 2024-03-19 烽台科技(北京)有限公司 Asset identification method and computer device

Also Published As

Publication number Publication date
CN112671948A (en) 2021-04-16

Similar Documents

Publication Publication Date Title
WO2022142499A1 (en) Method and apparatus for determining region to which ip address belongs, and electronic device and storage medium
US11347787B2 (en) Image retrieval method and apparatus, system, server, and storage medium
WO2020042586A1 (en) Method and apparatus for generating address of smart contract, computer device, and readable storage medium
JP6816275B2 (en) Domain name analysis method, server and storage medium
WO2022126983A1 (en) Electronic report file export method, apparatus and device, and storage medium
CN113094370B (en) Data index construction method and device, storage medium and electronic equipment
CN107807989B (en) Small file processing method and device
CN108763536B (en) Database access method and device
CN109144514B (en) JSON format data analysis and storage method and device
CN111416880A (en) IP address addressing method and device, computer storage medium and electronic equipment
WO2020088262A1 (en) Data analysis method and device, and storage medium
WO2023160137A1 (en) Graph data storage method and system, and computer device
WO2022199400A1 (en) Method and apparatus for retrieving persistent memory file system metadata, and storage structure
CN111694793A (en) Log storage method and device and log query method and device
CN113111239A (en) Universal database operation method, device and storage medium thereof
CN111125216A (en) Method and device for importing data into Phoenix
WO2022253131A1 (en) Data parsing method and apparatus, computer device, and storage medium
CN111026762A (en) Red and black tree index generation method and device, electronic equipment and storage medium
WO2022078001A1 (en) Method and apparatus for managing static rule, and electronic device and storage medium
CN115795187A (en) Resource access method, device and equipment
CN110569243B (en) Data query method, data query plug-in and data query server
CN113612869A (en) Short network address generation method, terminal and storage medium
CN114816219A (en) Data writing and reading method and device and data reading and writing system
CN104778197A (en) Data searching method and device
CN113760845A (en) Log processing method, system, device, client and storage medium

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21913244

Country of ref document: EP

Kind code of ref document: A1