CN110266834B - Area searching method and device based on internet protocol address - Google Patents

Area searching method and device based on internet protocol address Download PDF

Info

Publication number
CN110266834B
CN110266834B CN201910688369.9A CN201910688369A CN110266834B CN 110266834 B CN110266834 B CN 110266834B CN 201910688369 A CN201910688369 A CN 201910688369A CN 110266834 B CN110266834 B CN 110266834B
Authority
CN
China
Prior art keywords
internet protocol
protocol address
segment
ending
area number
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910688369.9A
Other languages
Chinese (zh)
Other versions
CN110266834A (en
Inventor
卢健
沈晓敏
黄红艳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN201910688369.9A priority Critical patent/CN110266834B/en
Publication of CN110266834A publication Critical patent/CN110266834A/en
Application granted granted Critical
Publication of CN110266834B publication Critical patent/CN110266834B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • H04L45/7453Address table lookup; Address filtering using hashing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2101/00Indexing scheme associated with group H04L61/00
    • H04L2101/60Types of network addresses
    • H04L2101/604Address structures or formats
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2101/00Indexing scheme associated with group H04L61/00
    • H04L2101/60Types of network addresses
    • H04L2101/69Types of network addresses using geographic information, e.g. room number

Abstract

The embodiment of the application provides a method and a device for searching a region based on an internet protocol address, wherein the method comprises the following steps: receiving a region searching instruction containing a target internet protocol address; converting the target Internet protocol address into a preset long and integer numerical value format to obtain a corresponding target character string; searching the matched area number in the first ordered three-dimensional array by using a binary search method, or searching the matched area number in a hash table; the first ordered three-dimensional array stores the corresponding relation between the character string and the area number corresponding to each Internet protocol address; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number; and outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number. The method and the device can effectively improve the efficiency of searching the corresponding area by using the IP address, and further can effectively improve the efficiency and the accuracy of positioning the IP address.

Description

Area searching method and device based on internet protocol address
Technical Field
The application relates to the technical field of data processing, in particular to a method and a device for searching for a region based on an internet protocol address.
Background
Internet Protocol Address (english: Internet Protocol Address is also translated into Internet Protocol Address) is abbreviated as IP Address (IP Address), and IP Address is a uniform Address format provided by IP Protocol, and allocates a logical Address to each network and each host on the Internet, so as to shield the difference of physical addresses.
In the risk monitoring process of money laundering prevention or fraud prevention in the financial industry, the problem of comparing whether two places are the same place according to the transaction IP is frequently encountered. At this time, the corresponding region needs to be searched according to the IP, but each region may have a plurality of IP intervals, and the intervals are not continuous. There are 64700 foreign IP intervals, and if the search is performed sequentially one by one, the efficiency is very low, and the real-time requirement of risk monitoring cannot be met basically, and the function of searching for areas is very important.
Therefore, it is highly desirable to design an efficient area search method.
Disclosure of Invention
Aiming at the problems in the prior art, the application provides a region searching method and device based on an internet protocol address, which can effectively improve the efficiency of searching a corresponding region by using an IP address, and further can effectively improve the efficiency and accuracy of positioning the IP address.
In order to solve the technical problem, the application provides the following technical scheme:
in a first aspect, the present application provides a method for finding a geographic area based on an internet protocol address, including:
receiving a region searching instruction, wherein the region searching instruction comprises a target internet protocol address;
converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
searching the area number matched with the target character string in a preset first ordered three-dimensional array by using a binary search method, or searching the area number matched with the target character string in a preset hash table;
the first ordered three-dimensional array stores the corresponding relation between the character strings and the area numbers corresponding to the internet protocol addresses; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number;
and outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number.
Further, before the receiving the region search instruction, the method further includes:
acquiring each area number and at least one internet protocol address corresponding to each area number;
and generating a corresponding first ordered three-dimensional array by applying the area numbers and at least one internet protocol address corresponding to each area number.
Further, the applying the area numbers and the at least one internet protocol address corresponding to each area number generates a corresponding first ordered three-dimensional array, including:
converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule;
determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each area number;
sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results;
and each line in the first ordered three-dimensional array stores one area number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the area number respectively.
Further, the converting, according to a preset first string conversion rule, each internet protocol address into a corresponding string includes:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit character string;
and deleting 0 which appears before the first non-0 digit in each twelve-bit character string which begins with 0 to obtain a character string which corresponds to each Internet protocol address.
Further, before the receiving the region search instruction, the method further includes:
acquiring each area number and at least one internet protocol address corresponding to each area number;
and generating a corresponding hash table by applying each region number and at least one internet protocol address corresponding to each region number.
Further, the generating a corresponding hash table by applying the area numbers and at least one internet protocol address corresponding to each area number includes:
converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule;
determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each area number;
sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results;
each line in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the region number respectively;
converting each character string in the second ordered three-dimensional array into a corresponding number segment, wherein the number segment consists of four numbers, and the number in each segment is less than or equal to three digits;
and applying the digital section, generating at least one address index corresponding to each region number according to a preset index establishing rule, and generating a hash table containing each index.
Further, the converting, according to a preset second string conversion rule, each internet protocol address into a corresponding string includes:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each of the twelve-bit strings.
Further, the converting each of the character strings in the second ordered three-dimensional array into a corresponding number segment includes:
dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers;
and deleting 0 which appears before the first non-0 digit from the three-digit number beginning with 0 in each segment, and if all the segments which are 0 exist, reserving one 0 to obtain the digital field corresponding to each twelve-bit character string.
Further, the applying the number segment, generating at least one address index corresponding to each of the area numbers according to a preset index establishment rule, and generating a hash table including each of the indexes includes:
selecting a region number as a current target region number;
and the step of acquiring the address index is executed: selecting a first appearing value and a segment different from each other in the starting internet protocol address or the ending internet protocol address from the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number in a left-to-right sequence, and determining the first appearing value and the segment different from each other as a target segment corresponding to the target area number; starting from the last-but-one section in the digital fields corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, applying the target section to sequentially obtain all address indexes corresponding to the target area number;
and updating the area number as the current target area number, and re-executing the step of acquiring the address index until at least one address index corresponding to each area number is acquired.
In a second aspect, the present application provides an apparatus for searching for a geographic area based on an internet protocol address, including:
the system comprises an instruction receiving module, a processing module and a processing module, wherein the instruction receiving module is used for receiving a region searching instruction, and the region searching instruction comprises a target internet protocol address;
the character string conversion module is used for converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
the area number searching module is used for searching an area number matched with the target character string in a preset first ordered three-dimensional array by applying a binary searching method, or searching an area number matched with the target character string in a preset hash table;
the first ordered three-dimensional array stores the corresponding relation between the character strings and the area numbers corresponding to the internet protocol addresses; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number;
and the coding output module is used for outputting the region number matched with the target character string so as to determine the region of the target Internet protocol address according to the region number.
Further, still include:
the internet protocol address acquisition module is used for acquiring each area number and at least one internet protocol address corresponding to each area number;
and the first ordered three-dimensional array generating module is used for generating a corresponding first ordered three-dimensional array by applying each region number and at least one internet protocol address corresponding to each region number.
Further, the first ordered three-dimensional array generating module comprises:
the first character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule;
the first character string corresponding unit is used for determining a character string of a starting Internet protocol address and a character string of an ending Internet protocol address corresponding to each area number;
the first sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results;
and each line in the first ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address, wherein the region number corresponds to the character string of the starting internet protocol address and the character string of the ending internet protocol address respectively.
Further, the first character string converting unit is specifically configured to execute the following:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit character string;
and deleting 0 which appears before the first non-0 digit in each twelve-bit character string beginning with 0 to obtain a character string corresponding to each Internet protocol address.
Further, still include:
the internet protocol address acquisition module is used for acquiring each area number and at least one internet protocol address corresponding to each area number;
and the hash table generation module is used for applying each region number and at least one internet protocol address corresponding to each region number to generate a corresponding hash table.
Further, the hash table generation module includes:
the second character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule;
the second character string corresponding unit is used for determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each region number;
the second sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results;
each line in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address, wherein the region number corresponds to the character string of the starting internet protocol address and the character string of the ending internet protocol address respectively;
the digital section conversion unit is used for converting each character string in the second ordered three-dimensional array into a corresponding digital section, wherein the digital section consists of four sections of numbers, and the number in each section is less than or equal to three digits;
and the address index establishing unit is used for applying the digital field, generating at least one address index corresponding to each area number according to a preset index establishing rule and generating a hash table containing each index.
Further, the second string converting unit is specifically configured to execute the following:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit string.
Further, the digital segment conversion unit is specifically configured to perform the following:
dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers;
and deleting 0 which appears before the first non-0 digit from the three-digit number beginning with 0 in each segment, and if all the segments which are 0 exist, reserving one 0 to obtain the digital field corresponding to each twelve-bit character string.
Further, the address index establishing unit is specifically configured to execute the following:
selecting a region number as a current target region number;
and the step of acquiring the address index is executed: selecting a first appearing value and a segment different from each other in the starting internet protocol address or the ending internet protocol address from the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number in a left-to-right sequence, and determining the first appearing value and the segment different from each other as a target segment corresponding to the target area number; starting from the last-but-one section in the digital fields corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, applying the target section to sequentially obtain all address indexes corresponding to the target area number;
and updating the area number as the current target area number, and re-executing the step of acquiring the address index until at least one address index corresponding to each area number is acquired.
In a third aspect, the present application provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for finding a geographic area based on an internet protocol address when executing the computer program.
In a fourth aspect, the present application provides a computer readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the internet protocol address based locale lookup method.
According to the technical scheme, the area searching method and device based on the internet protocol address, provided by the application, comprise the following steps: receiving a region searching instruction containing a target internet protocol address; converting the target Internet protocol address into a preset long and integer numerical value format to obtain a corresponding target character string; searching the matched area number in the first ordered three-dimensional array by using a binary search method, or searching the matched area number in a hash table; the first ordered three-dimensional array stores the corresponding relation between the character string and the area number corresponding to each Internet protocol address; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number; the area number matched with the target character string is output so as to determine the area where the target Internet protocol address is located according to the area number, the efficiency of searching the corresponding area by using the IP address can be effectively improved, the reliability of the searching process is high, the accuracy of the searching result is high, the efficiency and the accuracy of positioning the IP address can be effectively improved, and the efficiency and the accuracy of risk monitoring such as anti-money laundering or anti-fraud and the like according to the positioning result can be effectively improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic diagram illustrating an architecture of a geographic search device based on an internet protocol address according to the present application.
Fig. 2 is a flowchart illustrating a method for finding a geographic area based on an internet protocol address according to an embodiment of the present disclosure.
Fig. 3 is a schematic flowchart of steps 010 and 020 in the internet protocol address-based region search method in the embodiment of the present application.
Fig. 4 is a flowchart illustrating a step 020 in a geographic search method based on an internet protocol address according to an embodiment of the present application.
Fig. 5 is a flowchart illustrating a step 021 in the ip address based locality search method according to this embodiment.
Fig. 6 is a flowchart illustrating step 030 and step 040 in the internet protocol address-based locality search method in the embodiment of the present application.
Fig. 7 is a flowchart illustrating step 040 in the internet protocol address-based locality searching method according to the embodiment of the present application.
Fig. 8 is a schematic flowchart of step 041 in the internet protocol address-based region search method in the embodiment of the present application.
Fig. 9 is a flowchart illustrating step 044 in the internet protocol address-based locality search method in the embodiment of the present application.
Fig. 10 is a flowchart illustrating a step 045 in a method for searching for a geographic area based on an internet protocol address according to an embodiment of the present invention.
Fig. 11 is a schematic structural diagram of a geographic search apparatus based on an internet protocol address in an embodiment of the present application.
Fig. 12 is a schematic structural diagram of an electronic device in an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
In consideration of the existing risk monitoring process of money laundering or fraud prevention in the financial industry, the problem of comparing whether two sites are the same site according to the transaction IP is often encountered. At this time, the corresponding region needs to be searched according to the IP, but each region may have a plurality of IP intervals, and the intervals are not continuous. Only 64700 foreign IP intervals exist, if the search is carried out one by one in sequence, the efficiency is very low, the requirement of the real-time performance of risk monitoring cannot be basically met, and the function of searching the region is very important, so that the application provides a region search method based on an Internet protocol address, a region search device based on the Internet protocol address, an electronic device and a computer readable storage medium, and by receiving a region search instruction, the region search instruction comprises a target Internet protocol address; converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol; searching the area number matched with the target character string in a preset first ordered three-dimensional array by using a binary search method, or searching the area number matched with the target character string in a preset hash table;
wherein, the 11 stores the corresponding relation between the character string and the area number corresponding to each internet protocol address; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number; the area number matched with the target character string is output to determine the area where the target internet protocol address is located according to the area number, the efficiency of searching the corresponding area by using the IP address can be effectively improved, the reliability of the searching process is high, the accuracy of the searching result is high, the efficiency and the accuracy of positioning the IP address can be effectively improved, and the efficiency and the accuracy of risk monitoring such as money laundering or fraud prevention can be effectively improved according to the positioning result.
In view of the above, the embodiment of the present application provides an internet protocol address based region finding apparatus for implementing an internet protocol address based region finding method, where the internet protocol address based region finding apparatus may be a server 01, and referring to fig. 1, the server 01 may be communicatively connected between at least one database 02 for providing relevant data, and may also be communicatively connected with at least one client device 03.
Based on the above content, the server 01 may receive an area search instruction including a target internet protocol address from the client device 03 on line, then the server 01 converts the target internet protocol address into a preset long and integer numerical format to obtain a target character string corresponding to the target internet protocol, the server 01 may obtain a corresponding first ordered three-dimensional array from the database 02 on line, and search an area number matched with the target character string in the preset first ordered three-dimensional array by applying a binary search method, or search an area number matched with the target character string in a preset hash table; the first ordered three-dimensional array stores the corresponding relation between the character strings and the area numbers corresponding to the internet protocol addresses; the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the area number; then, the server 01 sends the area number matched with the target character string to the client 02, and the client 02 determines the area where the target internet protocol address is located according to the area number.
On this basis, after the client 02 determines the region where the target internet protocol address is located according to the region number, the client compares whether each target internet protocol address of the target user in a preset time period is in the same region or whether each target internet protocol address is in each region of the same country, and judges whether the target user has behaviors such as money laundering or fraud prevention according to the comparison result by using a preset risk monitoring model such as money laundering or fraud prevention.
It is to be appreciated that the client devices may include smart phones, tablet electronic devices, network set-top boxes, portable computers, desktop computers, Personal Digital Assistants (PDAs), vehicle mounted devices, smart wearable devices, and the like. Wherein, intelligence wearing equipment can include intelligent glasses, intelligent wrist-watch, intelligent bracelet etc..
In practical applications, part of the internet protocol address based lookup of the locality may be performed on the server side as described above, or all operations may be performed in the client device. The selection may be specifically performed according to the processing capability of the client device, the limitation of the user usage scenario, and the like. This is not a limitation of the present application. The client device may further include a processor if all operations are performed in the client device.
The client device may have a communication module (i.e., a communication unit), and may be communicatively connected to a remote server to implement data transmission with the server. The server may include a server on the task scheduling center side, and in other implementation scenarios, the server may also include a server on an intermediate platform, for example, a server on a third-party server platform that is communicatively linked to the task scheduling center server. The server may include a single computer device, or may include a server cluster formed by a plurality of servers, or a server structure of a distributed apparatus.
The server and the client device may communicate using any suitable network protocol, including network protocols not yet developed at the filing date of this application. The network protocol may include, for example, a TCP/IP protocol, a UDP/IP protocol, an HTTP protocol, an HTTPS protocol, or the like. Of course, the network Protocol may also include, for example, an RPC Protocol (Remote Procedure Call Protocol), a REST Protocol (Representational State Transfer Protocol), and the like used above the above Protocol.
In order to effectively improve the efficiency of searching for a corresponding region by using an IP address and further effectively improve the efficiency and accuracy of locating the IP address, the present application provides an embodiment of an internet protocol address-based region searching method, where an execution subject may be the aforementioned server or client, and referring to fig. 2, the internet protocol address-based region searching method specifically includes the following contents:
step 100: and receiving a region searching instruction, wherein the region searching instruction comprises a target internet protocol address.
Step 200: converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
step 300: and searching the area number matched with the target character string in a preset first ordered three-dimensional array by using a binary search method, or searching the area number matched with the target character string in a preset hash table.
It can be understood that the first ordered three-dimensional array stores the corresponding relationship between the character strings and the area numbers corresponding to the internet protocol addresses; and the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the region number.
Step 400: and outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number.
In order to improve the application reliability of the first ordered three-dimensional array, so as to further improve the efficiency of searching for the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching for a region based on an internet protocol address according to the present application, referring to fig. 3, before step 100 of the method for searching for a region based on an internet protocol address, the following contents are further specifically included:
step 010: and acquiring each area number and at least one internet protocol address corresponding to each area number.
Step 020: and generating a corresponding first ordered three-dimensional array by applying the area numbers and at least one internet protocol address corresponding to each area number.
In order to effectively improve the accuracy of obtaining an internet protocol address, so as to further improve the efficiency of searching a corresponding region by using an IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching a region based on an internet protocol address, referring to fig. 4, the step 020 specifically includes the following steps:
step 021: and converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule.
Step 022: and determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each region number.
Step 023: and sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results.
It can be understood that each row in the first ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to the region number respectively.
In order to effectively improve the accuracy and reliability of the character string conversion, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching the region based on the internet protocol address, referring to fig. 5, the step 021 specifically includes the following contents:
step 0211: and adding a 0 after the first separation point, wherein the number between every two points in each internet protocol address is added into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address.
Step 0212: deleting each separation point in each twelve-bit string.
Step 0213: and deleting 0 which appears before the first non-0 digit in each twelve-bit character string beginning with 0 to obtain a character string corresponding to each Internet protocol address.
In order to improve the reliability of the hash table, so as to further improve the efficiency of searching for the corresponding area by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the internet protocol address-based area searching method according to the present application, referring to fig. 6, before step 100 of the internet protocol address-based area searching method, the following contents are further specifically included:
step 030: and acquiring each region number and at least one Internet protocol address corresponding to each region number.
Step 040: and generating a corresponding hash table by applying each region number and at least one internet protocol address corresponding to each region number.
In order to improve the obtaining efficiency and accuracy of the hash table, so as to further improve the efficiency of searching for the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the internet protocol address-based region searching method according to the present application, referring to fig. 7, the step 040 specifically includes the following contents:
step 041: and converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule.
Step 042: and determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each region number.
Step 043: and sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results.
It can be understood that each row in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to the region number respectively.
Step 044: and converting each character string in the second ordered three-dimensional array into a corresponding number segment, wherein the number segment consists of four segments of numbers, and the number in each segment is less than or equal to three digits.
Step 045: and applying the digital field, generating at least one address index corresponding to each area number according to a preset index establishing rule, and generating a hash table containing each index.
In order to effectively improve the accuracy and reliability of the character string conversion, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching the region based on the internet protocol address, referring to fig. 8, the step 041 specifically includes the following contents:
step 0411: and adding 0 after the first separation point, wherein the number between every two points in each internet protocol address is added into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address.
Step 0412: deleting each separation point in each twelve-bit string.
In order to effectively improve the reliability of digital field conversion, so as to further improve the efficiency of searching for a corresponding region by using an IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching for a region based on an internet protocol address according to the present application, referring to fig. 9, the step 044 specifically includes the following contents:
step 0441: dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers.
Step 0442: and deleting 0 which appears before the first non-0 digit from the three-digit number beginning with 0 in each segment, and if all the segments which are 0 exist, reserving one 0 to obtain the digital field corresponding to each twelve-bit character string.
In order to effectively improve the reliability of the hash table, so as to further improve the efficiency of searching the corresponding area by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the method for searching an area based on an internet protocol address according to the present application, referring to fig. 10, the step 045 specifically includes the following contents:
step 0451: a region number is selected as the current target region number.
Step 0452: and the step of acquiring the address index is executed: selecting a first appearing value and a segment different from each other in the starting internet protocol address or the ending internet protocol address from the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number in a left-to-right sequence, and determining the first appearing value and the segment different from each other as a target segment corresponding to the target area number; starting from the last-but-one section in the digital fields corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, applying the target section to sequentially obtain all address indexes corresponding to the target area number;
step 0453: and updating the area number as the current target area number, and re-executing the step of acquiring the address index until at least one address index corresponding to each area number is acquired.
To further explain the scheme, the present application further provides a specific application example of a method for searching for a region number corresponding to an internet protocol address by applying a dichotomy, which specifically includes the following contents:
first, the IP is converted to a long integer numerical format. The conversion method is to fill up 3 bits for an IP segment less than 3 bits, and then remove the middle ". multidot.. For example: the IP of "192.168.0.1" is converted into 192168000001, and the IP of "84.232.79.91" is converted into 84232079091.
And (II) sorting the converted IP intervals from small to large, and storing the IP intervals into an ordered 3-dimensional array with the length of n. The 3 dimensions represent the start IP, end IP and region number, respectively, as shown in table 1:
TABLE 1
Initiating IP Terminating IP Region number
1011000000 1011255255 410
1016000000 1019255255 410
1020000000 1020255255 764
1021000000 1021255255 392
1022000000 1023255255 356
And (III) searching any IP by using a binary search idea. The searching steps are as follows:
s1: judging whether the IP section belongs to the middle IP section of the ordered array:
if the IP section belongs to the area corresponding to the middle IP section, returning to the middle IP section.
Otherwise, perform S2 and S3:
s2: if the number of the last half section of the array is larger than the end IP of the middle IP section, intercepting the second half section of the array as a new array;
s3: if the initial IP is smaller than the initial IP of the middle IP section, intercepting the first half section of the array as a new array;
the above search operation is repeated from the resulting new array.
The search space can be reduced by half each time by searching through the method, the time complexity (the maximum number of times of inquiry) is O (log2(n)), and the region can be found by searching for 16 times at most under the condition that n is 64700 IP segments. The real-time requirement can be basically met.
To further illustrate the above scheme, the present application further provides a specific application example for obtaining a region number corresponding to a target IP by applying a hash lookup manner, where the specific contents are as follows:
1. the IP is converted into a string. The conversion rule is: make up 3 bits for IP segments with less than 3 bits, and then remove the middle ". -.
2. By reasonably intercepting the string from left to right, minimally indexing, and storing into the HASH table (keys are intercepted IP strings, values are regions). The time complexity (number of lookups) of this method is O (1). The difficulty is how to minimize indexing, if the string is not intercepted, indexing every complete IP, and the space occupation would be a surprisingly large fourth power of 255.
The method of minimizing the index is to reasonably intercept the string. For example, table 2:
TABLE 2
Initiating IP Terminating IP Region number
001011000000 001011255255 410
The first six bits of the character can be intercepted to establish the index as "001011" and the corresponding value as "410", which reduces 255 x 255-1 indexes, and for the IP of the first six bits as "001011", no matter what value follows, the IP is necessarily the IP of the area of "410". But the reality is often much more complex and many IP segments do not fill the entire range like 0-255. For example, table 3:
TABLE 3
Initiating IP Terminating IP Region number
023002137101 023004092007 840
This involves splitting several indices of different lengths. Such as:
023003, the first six bits are 023003 and are guaranteed to belong to regions 840 and 023002138, and the first nine bits are 023002138 and are guaranteed to belong to regions 840; but not "023002137" because the first six bits "023002137" are not necessarily the region "840", such as "023002137100". The idea of the algorithm is to minimize the number of indexes created, but these indexes can map all the IP belonging to the area correctly.
The specific indexing algorithm is as follows.
The starting IP and the ending IP are firstly split into four segments according to one segment of every three bits and are stored by numbers. Such as:
"023002137101" in the above table is stored as [23,2,137,101 ]; "023004092007" is stored as [23,4,92,7 ].
Comparing two IPs differs from the first few segments, the example table is the second segment: 2 ≠ 4. All indices (minimal in number and can encompass all cases) for this IP segment are then generated using the following algorithm, as shown in table 4 below:
TABLE 4
Figure GDA0003747994930000161
The specific example corresponding to the application instance for obtaining the area number corresponding to the target IP by using the hash lookup manner is as follows:
(I) Format conversion
And converting each IP corresponding to each area number into a corresponding character string. The conversion rule is: make up 3 bits for IP segments with less than 3 bits, and then remove the middle ". -.
(II) ordered storage
And sequencing the IP region numbers converted into the corresponding character strings according to the numerical value sequence from small to large, and storing the sequenced IP regions converted into the corresponding character strings.
Conversion of (tri) digital fields
S1: splitting the IP converted into the corresponding character string into four segments according to each three-bit segment, deleting 0 positioned in front of the number in each segment, and storing the segment by using a number segment, wherein the number segment is abbreviated as: and (4) section.
S2: selecting a region number as a current target region number, and selecting from a first region number CODE1, wherein each segment of bytes of a starting IP corresponding to the first region number CODE1 are marked as A1-1, B1-1, C1-1 and D1-1; the first region number CODE1 corresponds to each segment byte A1-2, B1-2, C1-2 and D1-2 in the ending IP.
S3: determining bytes with different values in the bytes A1-1 to D1-1 of the start IP and the bytes A1-2 to D1-2 of the end IP in the target area number, selecting the segments with different values in the first of the start IP or the end IP in the order from left to right, and defining the segments as a target segment T1-12 common to the start IP and the end IP in the target area number.
(IV) establishing an index
S1: judging whether the current segment (fourth segment D1-1) of the start IP and the current segment (fourth segment D1-2) of the end IP corresponding to the target area number are the target segments;
if yes, it means that the values in the first three segments of the start IP and the end IP corresponding to the target region number are the same, and since the start IP and the end IP are arranged in the order of the values from small to large, it can be considered that the value in the current segment (fourth segment D1-1) of the start IP is smaller than the value in the current segment (fourth segment D1-2) of the end IP, and step S2 is performed;
if not, and the third segment C1-1 of the start IP and the third segment C1-2 of the end IP corresponding to the target region number are the target segments, then step S5 is performed;
if not, and the second segment B1-1 of the start IP and the second segment B1-2 of the end IP corresponding to the target region number are the target segments, executing the step S13;
s2: judging whether the value of the current segment (fourth segment D1-1) of the start IP corresponding to the target region number is not equal to 0 and whether the value of the current segment (fourth segment D1-2) in the end IP is not equal to 255;
if the value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target region number is not 0 and the value of the current segment (the fourth segment D1-2) in the end IP is not 255, then S3 is performed;
if the value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target region number is 0 and the value of the current segment (the fourth segment D1-2) in the end IP is equal to 255, then S4 is performed.
S3: and taking the four IP sections containing all four sections corresponding to all values in the current section (the fourth section D1-1) of the start IP and the current section (the fourth section D1-2) in the end IP corresponding to the target area number as the IP index of the current target area number.
For example, if the four segments corresponding to the start IP of the current target region number are [23.2.137.101], and the four segments in the end IP are [23.2.137.137], then [23.2.137.101], [23.2.137.102] … [23.2.137.137] are all used as the IP index of the current target region number.
S4: deleting the current segment (the fourth segment D1-1) of the starting IP and the current segment (the fourth segment D1-2) of the ending IP corresponding to the target area number, and taking the three segments of IP segments containing the first three segments in the remaining starting IP or ending IP as the IP index of the current target area number.
For example, if four segments corresponding to the start IP of the current target region number are [23.2.137.0] and four segments in the end IP are [23.2.137.255], then [23.2.137] is used as the IP index of the current target region number.
S5: judging the size relationship between the numerical value of the current segment (the fourth segment D1-1) of the starting IP and the numerical value of the current segment (the fourth segment D1-2) in the ending IP, which correspond to the target area number, and 0 and 255 respectively;
if the value of the current segment (fourth segment D1-1) of the start IP corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment (fourth segment D1-2) of the end IP corresponding to the target area number is not 255 and is not 0, then S6 is performed;
if the value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target area number is 0, and if the value of the current segment (the fourth segment D1-2) of the end IP corresponding to the target area number is 255, then S10 is performed;
if the value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target area number is 255 and if the value of the current segment (the fourth segment D1-2) of the end IP corresponding to the target area number is 255, then S11 is performed;
if the value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target area number is 0, and if the value of the current segment (the fourth segment D1-2) of the end IP corresponding to the target area number is also 0, then S12 is performed;
s6: for the four IP segments including all four segments corresponding to the values between the current value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target region number and 255, the first IP index subset of the current target region number is executed S7.
For example, if four segments corresponding to the start IP of the current target region number are [23.2.24.101], then [23.2.24.101], [23.2.24.102] … … [23.2.24.255] are used as the first IP index subset of the current target region number.
S7: four IP segments including all four segments corresponding to the value between 0 and the current value of the current segment (the fourth segment D1-2) of the ending IP corresponding to the target region number are used as the second IP index subset of the current target region number, and then S8 is performed.
For example, if four segments in the end IP of the current target region number are [23.2.127.137], then [23.2.127.0], [23.2.127.2] … … [23.2.127.137] are used as the second IP index sub-group of the current target region number.
S8: deleting the current segment (fourth segment D1-1) of the starting IP and the current segment (fourth segment D1-2) in the ending IP, adding 1 to the numerical value of the previous segment (namely, the third segment C1-1) of the current segment (fourth segment D1-1) of the starting IP corresponding to the target area number to obtain the corresponding starting three-segment IP segment containing the first to third segments, subtracting 1 from the numerical value of the previous segment of the current segment (fourth segment D1-2) in the ending IP corresponding to the target area number to obtain the corresponding ending three-segment IP segment containing the first to third segments, then using all three segments including the starting three-segment IP segment to the ending three-segment IP as the third IP index subgroup of the current target area number, and then executing S9.
For example, if the four segments corresponding to the start IP of the current target region number are [23.2.24.101], the four segments in the end IP are [23.2.127.137], the first IP index subset is [23.2.24.101], [23.2.24.102] … … [23.2.24.255], the second IP index subset is [23.2.127.0], [23.2.127.1] … … [23.2.127.137], and the third IP index subset of the current target region number is [23.2.25], [23.2.26] … [23.2.24.126 ].
S9: and forming the first IP index subgroup, the second IP index subgroup and the third IP index subgroup in the S7-S8 into the IP index corresponding to the current target region number.
For example, if the four segments corresponding to the start IP of the current target region number are [23.2.24.101], the fourth segment in the end IP is [23.2.127.137], the first IP index subset is [23.2.24.101], [23.2.24.102] … … [23.2.24.255], the second IP index subset is [23.2.127.0], [23.2.127.1] … … [23.2.127.137], the third IP index subset is [23.2.25], [23.2.26] … [23.2.126], and the IP index corresponding to the current target region number is shown in table 5.
TABLE 5
Figure GDA0003747994930000191
S10: deleting the current segment (fourth segment D1-1) of the starting IP and the current segment (fourth segment D1-2) of the ending IP, generating a starting three-segment IP segment comprising the first segment to the third segment of the starting IP, generating an ending three-segment IP segment comprising the first segment to the third segment of the ending IP, and then taking all three segments of IP segments comprising the starting three-segment IP segment to the ending three-segment IP as IP indexes of the current target area number.
For example, if the four segments of the start IP of the current target region number are [23.2.24.0], and the four segments of the end IP are [23.2.127.255], the IP indexes of the current target region number are [23.2.24], [23.2.25] … [23.2.127 ].
S11: taking the four IP sections corresponding to the current section (the fourth section D1-1) of the starting IP as one of the IP indexes of the current target area number, deleting the current section (the fourth section D1-1) of the starting IP and the current section (the fourth section D1-2) in the ending IP, adding 1 to the value of the previous section (namely, the third section C1-1) of the current section (the fourth section D1-1) of the starting IP corresponding to the target area number to obtain the corresponding starting three IP sections containing the first to the third sections, taking the ending three IP sections of the first to the third sections of the ending IP corresponding to the target area number, and taking all three IP sections including the four IP sections and the three IP sections as the IP indexes of the current target area number.
For example, if the four segments of the start IP of the current target region number are [23.2.24.255], and the four segments of the end IP are [23.2.127.255], the IP index corresponding to the current target region number is [23.2.24.255], which further includes [23.2.25], [23.2.26] … [23.2.127 ].
S12: taking the four IP sections corresponding to the current section (the fourth section D1-2) in the ending IP as one of the IP indexes of the current target area number, deleting the current section (the fourth section D1-1) of the starting IP and the current section (the fourth section D1-2) in the ending IP, obtaining the starting three IP sections which comprise the first to the third sections and correspond to the starting IP, subtracting 1 from the value of the previous section (namely the third section C1-1) of the current section (the fourth section D1-2) of the ending IP corresponding to the target area number to obtain the ending three IP sections which correspond to the first to the third sections of the ending IP, and taking all three IP sections which comprise the four IP sections and the three IP sections as the IP indexes of the current target area number.
For example, if the four segments of the start IP of the current target region number are [23.2.24.0], and the four segments of the end IP are [23.2.127.0], the IP index corresponding to the current target region number is [23.2.127.0], which further includes [23.2.24], [23.2.25] … [23.2.126 ].
S13: judging the size relationship between the numerical value of the current segment (the fourth segment D1-1) of the starting IP and the numerical value of the current segment (the fourth segment D1-2) in the ending IP, which correspond to the target area number, and 0 and 255 respectively;
if the value of the current segment (fourth segment D1-1) of the start IP corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment (fourth segment D1-2) of the end IP corresponding to the target area number is not 255 and is not 0, then S14 is performed;
s14: for the four IP segments including all four segments corresponding to the values between the current value of the current segment (the fourth segment D1-1) of the start IP corresponding to the target region number and 255, the first IP index subset of the current target region number is executed S15.
For example, if the four segments corresponding to the start IP of the current target region number are [23.2.24.101], then [23.2.24.101], [23.2.24.102] … … [23.2.24.255] are used as the first IP index subgroup of the current target region number.
S15: and regarding the four IP segments including all four segments corresponding to the value between 0 and the current value of the current segment (the fourth segment D1-2) of the ending IP corresponding to the target region number as the second IP index subgroup of the current target region number, and then executing S16.
For example, if four segments in the end IP of the current target region number are [23.14.127.137], then [23.14.127.0], [23.14.127.2] … … [23.14.127.137] are used as the second IP index sub-group of the current target region number.
S16: deleting the current segment (fourth segment D1-1) of the starting IP and the current segment (fourth segment D1-2) of the ending IP, adding 1 to the value of the previous segment (namely, the third segment C1-1) of the current segment (fourth segment D1-1) of the starting IP corresponding to the target region number to obtain the corresponding starting three-segment IP segment containing the first to third segments, subtracting 1 from the value of the previous segment of the current segment (fourth segment D1-2) of the ending IP corresponding to the target region number to obtain the corresponding ending three-segment IP segment containing the first to third segments, then forming the starting three-segment IP segment and the ending three-segment IP segment into new starting IP and ending IP, wherein the new starting IP and ending IP only contain the contents of the first segment to the third segment, and then executing the contents of the steps S6 to S12 to the new starting IP and ending IP, i.e., the aforementioned current segment of the initial IP is replaced with the third segment C1-1, and the aforementioned current segment of the ending IP is replaced with the third segment C1-2.
For example, if the four segments corresponding to the start IP of the current target region number are [23.2.24.101], the four segments in the end IP are [23.2.127.137], the first IP index subset is [23.2.24.101], [23.2.24.102] … … [23.2.24.255], the second IP index subset is [23.14.127.0], [23.14.127.1] … … [23.14.127.137], the new start IP of the current target region number is [23.2.25], and the new end IP is [23.14.126 ]; then further judging whether the last bit given in the [23.2.25] and the [23.14.126] is not 0 or 255, and acquiring a first IP index subgroup of a new initial IP, wherein the first IP index subgroup is [23.2.25], [23.2.26] … [23.2.255 ]; the second IP index subgroup of the ending IP is [23.14.0], [23.14.1] … [23.14.126], and the third IP index subgroup is [23.3], [23.4] … [23.13 ].
Based on this, if the start IP of the target region number is [23.2.24.101], and the four segments of the end IP are [23.14.127.137], the IP index corresponding to the current target region number is as shown in table 6.
TABLE 6
Figure GDA0003747994930000211
Figure GDA0003747994930000221
Based on the above, similarly, if the values in the segments in the starting IP and the ending IP are different, although the probability of the occurrence of the situation is very low, the corresponding index can still be established for the situations by applying the above-described manner of the present application.
For example: if the start IP of the target region number is [23.2.24.101], and the four segments of the end IP are [28.14.127.137], the IP index corresponding to the current target region number is shown in table 7.
TABLE 7
Figure GDA0003747994930000222
(V) regional search
And searching the area number corresponding to the target IP by using a Hash algorithm according to the established index.
From the above description, it can be seen that the regional search method based on internet protocol addresses provided in the application example of the present application solves the problem of searching for a region by IP in the anti-money laundering modeling process. The real-time searching effect can be achieved, and meanwhile, the memory occupation is small. 1. The waiting time of program operation when modeling personnel do characteristic engineering is greatly shortened, and the working efficiency is improved. The method can achieve the instant effect and provide feasibility for prediction in the field. 3. This method is also applicable to other scenarios where similar problems are encountered.
In terms of software, in order to effectively improve the efficiency of searching for a corresponding area by using an IP address and further effectively improve the efficiency and accuracy of locating the IP address, the present application provides an embodiment of an internet protocol address-based area searching apparatus for implementing all or part of the contents in the above internet protocol address-based area searching method, referring to fig. 11, where the internet protocol address-based area searching apparatus specifically includes the following contents:
the instruction receiving module 10 is configured to receive a region search instruction, where the region search instruction includes a target internet protocol address.
And the character string conversion module 20 is configured to convert the target internet protocol address into a preset long and integer numerical format, so as to obtain a target character string corresponding to the target internet protocol.
The area number searching module 30 is configured to search, by applying a binary search method, an area number matched with the target character string in a preset first ordered three-dimensional array, or search, by applying a binary search method, an area number matched with the target character string in a preset hash table.
It can be understood that the first ordered three-dimensional array stores the corresponding relationship between the character strings and the area numbers corresponding to the internet protocol addresses; and the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the region number.
And the code output module 40 is configured to output the region number matched with the target character string, so as to determine, according to the region number, a region where the target internet protocol address is located.
The embodiment of the internet protocol address-based area search device provided in the embodiment of the present application may be specifically configured to execute the processing procedure of the embodiment of the internet protocol address-based area search method in the foregoing embodiment, and its functions are not described herein again, and reference may be made to the detailed description of the embodiment of the internet protocol address-based area search method.
As can be seen from the above description, the area search device based on the internet protocol address provided in the embodiment of the present application can effectively improve the efficiency of searching the corresponding area by using the IP address, and has high reliability in the search process and high accuracy of the search result, so that the efficiency and accuracy of positioning the IP address can be effectively improved, and the efficiency and accuracy of risk monitoring, such as anti-money laundering or anti-fraud, according to the positioning result can be effectively improved.
In order to improve the application reliability of the first ordered three-dimensional array, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the device for searching a region based on an internet protocol address of the present application, the device further specifically includes the following contents:
and the internet protocol address acquisition module is used for acquiring each area number and at least one internet protocol address corresponding to each area number.
And the first ordered three-dimensional array generating module is used for generating a corresponding first ordered three-dimensional array by applying each region number and at least one internet protocol address corresponding to each region number.
In order to effectively improve the accuracy of obtaining an internet protocol address, so as to further improve the efficiency of searching a corresponding region by using an IP address, and further effectively improve the efficiency and the accuracy of positioning the IP address, in an embodiment of the internet protocol address-based region searching device according to the present application, the first ordered three-dimensional array generating module specifically includes the following contents:
and the first character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule.
And the first character string corresponding unit is used for determining the character string of the starting internet protocol address and the character string of the ending internet protocol address corresponding to each region number.
And the first sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results.
It can be understood that each line in the first ordered three-dimensional array stores one region number, a character string of a starting internet protocol address corresponding to the region number, and a character string of an ending internet protocol address corresponding to the region number.
In order to effectively improve the accuracy and reliability of the character string conversion, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the internet protocol address-based region searching apparatus of the present application, the first character string conversion unit is specifically configured to execute the following contents:
and adding 0 after the first separation point, wherein the number between every two points in each internet protocol address is added into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address.
Deleting each separation point in each of the twelve-bit strings.
And deleting 0 which appears before the first non-0 digit in each twelve-bit character string which begins with 0 to obtain a character string which corresponds to each Internet protocol address.
In order to improve the application reliability of the hash table, so as to further improve the efficiency of searching for the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the device for searching for a region based on an internet protocol address according to the present application, the device further specifically includes the following contents:
and the internet protocol address acquisition module is used for acquiring each area number and at least one internet protocol address corresponding to each area number.
And the hash table generation module is used for applying the area numbers and at least one internet protocol address corresponding to each area number to generate a corresponding hash table.
In order to improve the obtaining efficiency and accuracy of the hash table, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of positioning the IP address, in an embodiment of the internet protocol address-based region searching apparatus according to the present application, the hash table generating module specifically includes the following contents:
and the second character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule.
And the second character string corresponding unit is used for determining the character string of the starting internet protocol address and the character string of the ending internet protocol address corresponding to each region number.
And the second sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results.
It can be understood that each row in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to the region number respectively.
And the digital section conversion unit is used for converting each character string in the second ordered three-dimensional array into a corresponding digital section, wherein the digital section consists of four sections of numbers, and the number in each section is less than or equal to three digits.
And the address index establishing unit is used for applying the digital field, generating at least one address index corresponding to each region number according to a preset index establishing rule and generating a hash table containing each index.
In order to effectively improve the accuracy and reliability of the character string conversion, so as to further improve the efficiency of searching the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the device for searching the region based on the internet protocol address, the second character string conversion unit is specifically configured to execute the following steps:
and adding 0 after the first separation point, wherein the number between every two points in each internet protocol address is added into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address.
Deleting each separation point in each of the twelve-bit strings.
In order to effectively improve the reliability of digital segment conversion, so as to further improve the efficiency of searching for a corresponding region by using an IP address, and further effectively improve the efficiency and accuracy of positioning the IP address, in an embodiment of the device for searching for a region based on an internet protocol address, the digital segment conversion unit specifically includes the following contents:
dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers.
And deleting 0 which appears before the first non-0 digit from the three-digit number beginning with 0 in each segment, and if all the segments which are 0 exist, reserving one 0 to obtain the digital field corresponding to each twelve-bit character string.
In order to effectively improve the application reliability of the hash table, so as to further improve the efficiency of searching for the corresponding region by using the IP address, and further effectively improve the efficiency and accuracy of locating the IP address, in an embodiment of the IP address-based region search apparatus according to the present application, the address index establishing unit is specifically configured to execute the following contents:
a region number is selected as the current target region number.
And the step of acquiring the address index is executed: selecting a first appearing value and a segment different from each other in the starting internet protocol address or the ending internet protocol address from the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number in a left-to-right sequence, and determining the first appearing value and the segment different from each other as a target segment corresponding to the target area number; and sequentially acquiring all address indexes corresponding to the target area number by applying the target section from the last section in the digital sections corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number.
And updating the area number as the current target area number, and re-executing the step of acquiring the address index until at least one address index corresponding to each area number is acquired.
In order to effectively improve the efficiency of searching for a corresponding region by using an IP address and further effectively improve the efficiency and accuracy of locating the IP address, an embodiment of an electronic device for implementing all or part of the contents in the method for searching for a region based on an internet protocol address is provided in the present application, where the electronic device specifically includes the following contents:
a processor (processor), a memory (memory), a communication Interface (Communications Interface), and a bus; the processor, the memory and the communication interface complete mutual communication through the bus; the communication interface is used for realizing information transmission among relevant equipment such as a region searching device based on an internet protocol address, various databases, a user terminal and the like; the electronic device may be a desktop computer, a tablet computer, a mobile terminal, and the like, but the embodiment is not limited thereto. In this embodiment, the electronic device may refer to an embodiment of the internet protocol address-based area search method and an embodiment of the internet protocol address-based area search apparatus in the embodiment for implementation, and the contents thereof are incorporated herein, and repeated details are not repeated.
Fig. 12 is a schematic block diagram of a system configuration of an electronic device 9600 according to the embodiment of the present application. As shown in fig. 12, the electronic device 9600 can include a central processor 9100 and a memory 9140; the memory 9140 is coupled to the central processor 9100. Notably, this fig. 12 is exemplary; other types of structures may also be used in addition to or in place of the structure to implement telecommunications or other functions.
In one embodiment, the internet protocol address based locale lookup functionality may be integrated into the central processor 9100. The central processor 9100 can be configured to perform the following control:
step 100: and receiving a region searching instruction, wherein the region searching instruction comprises a target internet protocol address.
Step 200: converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
step 300: and searching the area number matched with the target character string in a preset first ordered three-dimensional array by using a binary search method, or searching the area number matched with the target character string in a preset hash table.
It can be understood that the first ordered three-dimensional array stores the corresponding relationship between the character strings and the area numbers corresponding to the internet protocol addresses; and the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the region number.
Step 400: and outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number.
As can be seen from the above description, the electronic device provided in the embodiment of the present application can effectively improve the efficiency of searching the corresponding area by using the IP address, and has high reliability in the searching process and high accuracy of the search result, so that the efficiency and accuracy of positioning the IP address can be effectively improved, and the efficiency and accuracy of risk monitoring, such as anti-money laundering or anti-fraud, can be effectively improved according to the positioning result.
In another embodiment, the internet protocol address based locale lookup apparatus may be configured separately from the central processor 9100, for example, the internet protocol address based locale lookup apparatus may be configured as a chip connected to the central processor 9100 to implement the internet protocol address based locale lookup function under the control of the central processor.
As shown in fig. 12, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is noted that the electronic device 9600 also does not necessarily include all of the components shown in fig. 12; further, the electronic device 9600 may further include components not shown in fig. 12, which can be referred to in the related art.
As shown in fig. 12, a central processor 9100, sometimes referred to as a controller or operational control, can include a microprocessor or other processor device and/or logic device, which central processor 9100 receives input and controls the operation of the various components of the electronic device 9600.
The memory 9140 can be, for example, one or more of a buffer, a flash memory, a hard drive, a removable media, a volatile memory, a non-volatile memory, or other suitable device. The information relating to the failure may be stored, and a program for executing the information may be stored. And the central processing unit 9100 can execute the program stored in the memory 9140 to realize information storage or processing, or the like.
The input unit 9120 provides input to the central processor 9100. The input unit 9120 is, for example, a key or a touch input device. The power supply 9170 is used to provide power to the electronic device 9600. The display 9160 is used for displaying display objects such as images and characters. The display may be, for example, an LCD display, but is not limited thereto.
The memory 9140 can be a solid state memory, e.g., Read Only Memory (ROM), Random Access Memory (RAM), a SIM card, or the like. There may also be a memory that holds information even when power is off, can be selectively erased, and is provided with more data, an example of which is sometimes called an EPROM or the like. The memory 9140 could also be some other type of device. Memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application/function storage portion 9142, the application/function storage portion 9142 being used for storing application programs and function programs or for executing a flow of operations of the electronic device 9600 by the central processor 9100.
The memory 9140 can also include a data store 9143, the data store 9143 being used to store data, such as contacts, digital data, pictures, sounds, and/or any other data used by an electronic device. The driver storage portion 9144 of the memory 9140 may include various drivers for the electronic device for communication functions and/or for performing other functions of the electronic device (e.g., messaging applications, contact book applications, etc.).
The communication module 9110 is a transmitter/receiver 9110 that transmits and receives signals via an antenna 9111. The communication module (transmitter/receiver) 9110 is coupled to the central processor 9100 to provide input signals and receive output signals, which may be the same as in the case of a conventional mobile communication terminal.
A plurality of communication modules 9110, such as a cellular network module, a bluetooth module, and/or a wireless local area network module, can be provided in the same electronic device based on different communication technologies. The communication module (transmitter/receiver) 9110 is also coupled to a speaker 9131 and a microphone 9132 via an audio processor 9130 to provide audio output via the speaker 9131 and receive audio input from the microphone 9132, thereby implementing ordinary telecommunications functions. The audio processor 9130 may include any suitable buffers, decoders, amplifiers and so forth. In addition, the audio processor 9130 is also coupled to the central processor 9100, thereby enabling recording locally through the microphone 9132 and enabling locally stored sounds to be played through the speaker 9131.
An embodiment of the present application further provides a computer-readable storage medium capable of implementing all the steps in the internet protocol address based locality search method with a server or a client as an execution subject in the foregoing embodiments, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements all the steps in the internet protocol address based locality search method with a server or a client as an execution subject in the foregoing embodiments, for example, when the processor executes the computer program, the processor implements the following steps:
step 100: and receiving a region searching instruction, wherein the region searching instruction comprises a target internet protocol address.
Step 200: converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
step 300: and searching the area number matched with the target character string in a preset first ordered three-dimensional array by using a binary search method, or searching the area number matched with the target character string in a preset hash table.
It can be understood that the first ordered three-dimensional array stores the corresponding relationship between the character strings and the area numbers corresponding to the internet protocol addresses; and the hash table stores the corresponding relation between the index corresponding to each internet protocol address and the region number.
Step 400: and outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number.
As can be seen from the above description, the computer-readable storage medium provided in the embodiments of the present application can effectively improve the efficiency of searching a corresponding area using an IP address, and has high reliability in the searching process and high accuracy of the search result, so that the efficiency and accuracy of positioning the IP address can be effectively improved, and the efficiency and accuracy of risk monitoring, such as anti-money laundering or anti-fraud, according to the positioning result can be effectively improved.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The principle and the implementation mode of the invention are explained by applying specific embodiments in the invention, and the description of the embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (14)

1. A method for searching a region based on an Internet protocol address is characterized by comprising the following steps:
receiving a region searching instruction, wherein the region searching instruction comprises a target internet protocol address;
converting the target Internet protocol address into a preset long and integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
converting the target internet protocol address into a preset integer numerical format to obtain a target character string corresponding to the target internet protocol comprises: supplementing 3 bits to the address segment with the number less than 3 bits of the target Internet protocol address, and removing the middle separation point; a first address field of the target internet protocol address, beginning with 0 and less than 3 bits, is not zero-padded;
searching a region number matched with the target character string in a preset hash table;
wherein, the hash table stores the corresponding relationship between the index corresponding to each internet protocol address and the area number;
outputting the region number matched with the target character string to determine the region of the target Internet protocol address according to the region number;
before the receiving the region search instruction, the method further comprises:
acquiring each area number and at least one internet protocol address corresponding to each area number;
generating a corresponding hash table by applying each region number and at least one internet protocol address corresponding to each region number;
the generating a corresponding hash table by applying the area numbers and the at least one internet protocol address corresponding to each area number includes:
converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule;
determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each area number;
sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results;
each line in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the region number respectively;
converting each character string in the second ordered three-dimensional array into a corresponding number segment, wherein the number segment consists of four numbers, and the number in each segment is less than or equal to three digits;
applying the digital field, generating at least one address index corresponding to each area number according to a preset index establishing rule, and generating a hash table containing each index; the method comprises the following steps: selecting a region number as a current target region number;
and the step of acquiring the address index is executed: selecting a first appearing value and a segment different from each other in the starting internet protocol address or the ending internet protocol address from the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number in a left-to-right sequence, and determining the first appearing value and the segment different from each other as a target segment corresponding to the target area number; starting from the last-but-one section in the digital fields corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, applying the target section to sequentially obtain all address indexes corresponding to the target area number;
updating the area number as the current target area number, and re-executing the step of obtaining the address index until obtaining at least one address index corresponding to each area number;
the preset index establishment rule comprises the following steps:
s1: judging whether the current segment of the starting internet protocol address and the current segment of the ending internet protocol address corresponding to the target area number are the target segments or not in a reverse order from the fourth segment;
if yes, go to step S2;
if not, and the third segment of the starting internet protocol address and the third segment of the ending internet protocol address corresponding to the target area number are the target segments, executing step S5;
if not, and the second segment of the starting internet protocol address and the second segment of the ending internet protocol address corresponding to the target area number are the target segments, executing step S13;
s2: judging whether the value of the current segment of the starting internet protocol address corresponding to the target area number is not equal to 0 and whether the value of the current segment of the ending internet protocol address is not equal to 255;
if the value of the current segment of the starting internet protocol address corresponding to the target area number is not 0 and the value of the current segment of the ending internet protocol address is not 255, executing S3;
if the value of the current segment of the starting internet protocol address corresponding to the target region number is 0 and the value of the current segment of the ending internet protocol address is equal to 255, executing S4;
s3: taking the four segments of Internet protocol address segments which are corresponding to all numerical values in the current segment of the starting Internet protocol address and the current segment of the ending Internet protocol address and contain all four segments corresponding to the current segment of the starting Internet protocol address and the ending Internet protocol address corresponding to the target area number as the Internet protocol address index of the current target area number;
s4: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address corresponding to the target area number, and taking the three segments of the remaining starting internet protocol address or the ending internet protocol address containing the first three segments as the internet protocol address index of the current target area number;
s5: judging the magnitude relation between the numerical value of the current segment of the starting internet protocol address corresponding to the target area number and the numerical value of the current segment of the ending internet protocol address and 0 and 255 respectively;
if the value of the current segment of the starting ip address corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment of the ending ip address corresponding to the target area number is not 255 and is not 0, then S6 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 0, and if the value of the current segment of the ending ip address corresponding to the target area number is 255, then S10 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 255 and if the value of the current segment of the ending ip address corresponding to the target area number is 255, then S11 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 0, and if the value of the current segment of the ending ip address corresponding to the target area number is also 0, then S12 is executed;
s6: taking four segments of internet protocol address segments which contain all four segments and correspond to the values between the current value of the current segment of the initial internet protocol address corresponding to the target region number and 255 as a first internet protocol address index subgroup of the current target region number, and executing S7;
s7: taking four segments of internet protocol address segments including all four segments corresponding to the value between 0 and the current value of the current segment of the ending internet protocol address corresponding to the target area number as a second internet protocol address index subgroup of the current target area number, and then executing S8;
s8: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, adding 1 to the numerical value of the previous segment of the current segment of the starting internet protocol address corresponding to the target area number to obtain the corresponding starting three segments of internet protocol address segments containing the first to third segments, subtracting 1 from the numerical value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number to obtain the corresponding ending three segments of internet protocol address segments containing the first to third segments, taking all three segments of internet protocol address segments containing the starting three segments of internet protocol address segments to the ending three segments of internet protocol address segments as a third internet protocol address index subgroup of the current target area number, and then executing S9;
s9: forming an internet protocol address index corresponding to the current target area number by the first internet protocol address index subgroup, the second internet protocol address index subgroup and the third internet protocol address index subgroup in the S7-S8;
s10: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, generating a starting three-segment internet protocol address segment containing the first segment to the third segment of the starting internet protocol address, generating an ending three-segment internet protocol address segment containing the first segment to the third segment of the ending internet protocol address, and then taking all three internet protocol address segments containing the starting three-segment internet protocol address segment to the ending three-segment internet protocol address segment as the internet protocol address index of the current target area number;
s11: taking four segments of Internet protocol address segments corresponding to the current segment of the starting Internet protocol address as one of the Internet protocol address indexes of the current target area number, and deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, and adding 1 to the numerical value of the previous segment of the current segment of the initial internet protocol address corresponding to the target area number to obtain the corresponding initial three-segment internet protocol address segment containing the first segment to the third segment, and an ending three-segment Internet protocol address segment of the first segment to the third segment of the ending Internet protocol address corresponding to the target region number, then, all three Internet protocol address segments including the four Internet protocol address segments, the initial three Internet protocol address segments and the final three Internet protocol address segments are used as the Internet protocol address index of the current target area number;
s12: taking the four segments of Internet protocol address segments corresponding to the current segment in the ending Internet protocol address as one of the Internet protocol address indexes of the current target area number, and deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, and obtains a first three-segment internet protocol address segment including first to third segments corresponding to the first internet protocol address, and, subtracting 1 from the value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number, an ending three-segment internet protocol address segment of the first to third segments of the corresponding ending internet protocol address is obtained, then, all three Internet protocol address fields including the four Internet protocol address fields, the initial three Internet protocol address fields and the final three Internet protocol address fields are used as the Internet protocol address index of the current target area number;
s13: judging the magnitude relation between the numerical value of the current segment of the starting internet protocol address corresponding to the target area number and the numerical value of the current segment of the ending internet protocol address and 0 and 255 respectively;
if the value of the current segment of the starting ip address corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment of the ending ip address corresponding to the target area number is not 255 and is not 0, then S14 is executed;
s14: taking four segments of internet protocol address segments including all four segments corresponding to the values between the current value of the current segment of the starting internet protocol address corresponding to the target area number and 255 as a first internet protocol address index subgroup of the current target area number, and executing S15;
s15: four segments of internet protocol address segments which contain all four segments and correspond to the value between 0 of the current segment of the ending internet protocol address corresponding to the target area number and the current value are taken as a second internet protocol address index subgroup of the current target area number, and then S16 is executed;
s16: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, adding 1 to the numerical value of the previous segment of the current segment of the starting internet protocol address corresponding to the target area number to obtain the corresponding starting three-segment internet protocol address segment containing the first to the third segments, subtracting 1 from the numerical value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number to obtain the corresponding ending three-segment internet protocol address segment containing the first to the third segments, and then combining the starting three-segment internet protocol address segment and the ending three-segment internet protocol address segment into a new starting internet protocol address and an ending internet protocol address, wherein the new starting internet protocol address and the ending internet protocol address only contain the contents of the first segment to the third segment, the contents of the foregoing steps S6 to S12 are then performed on the new start internet protocol address and the end internet protocol address.
2. The internet protocol address based locale lookup method of claim 1 further comprising, prior to said receiving a locale lookup instruction:
acquiring each area number and at least one internet protocol address corresponding to each area number;
and generating a corresponding first ordered three-dimensional array by applying the area numbers and at least one internet protocol address corresponding to each area number.
3. The internet protocol address-based locality searching method of claim 2, wherein said applying said respective locality numbers and at least one respective internet protocol address corresponding to each of said locality numbers to generate a corresponding first ordered three-dimensional array comprises:
converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule;
determining a character string of a starting internet protocol address and a character string of an ending internet protocol address corresponding to each area number;
sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large, and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results;
and each line in the first ordered three-dimensional array stores one area number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the area number respectively.
4. The internet protocol address-based locality search method of claim 3, wherein the converting each internet protocol address into a corresponding string according to a preset first string conversion rule comprises:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit character string;
and deleting 0 which appears before the first non-0 digit in each twelve-bit character string which begins with 0 to obtain a character string which corresponds to each Internet protocol address.
5. The internet protocol address-based locality searching method of claim 1, wherein the converting each internet protocol address into a corresponding string according to a preset second string conversion rule comprises:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit string.
6. The internet protocol address-based locality lookup method of claim 5, wherein said translating each of said character strings in said second ordered three-dimensional array into a corresponding number field comprises:
dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers;
and deleting 0 which appears before the first non-0 digit from the three digits beginning with 0 in each segment, and if all the segments which are 0 exist, keeping one 0 to obtain the digital fields corresponding to the twelve-bit character strings respectively.
7. An apparatus for searching for a geographic area based on an internet protocol address, comprising:
the system comprises an instruction receiving module, a processing module and a processing module, wherein the instruction receiving module is used for receiving a region searching instruction, and the region searching instruction comprises a target internet protocol address;
the character string conversion module is used for converting the target Internet protocol address into a preset long integer numerical value format to obtain a target character string corresponding to the target Internet protocol;
converting the target internet protocol address into a preset integer numerical format to obtain a target character string corresponding to the target internet protocol comprises: supplementing 3 bits to the address segment with the number less than 3 bits of the target Internet protocol address, and removing the middle separation point; a first address field of the target internet protocol address, beginning with 0 and less than 3 bits, is not zero-padded;
the region number searching module is used for searching a region number matched with the target character string in a preset hash table;
wherein, the hash table stores the corresponding relationship between the index corresponding to each internet protocol address and the area number;
the coding output module is used for outputting the region number matched with the target character string so as to determine the region of the target Internet protocol address according to the region number;
further comprising:
the internet protocol address acquisition module is used for acquiring each area number and at least one internet protocol address corresponding to each area number;
a hash table generation module, configured to apply the area numbers and at least one internet protocol address corresponding to each area number to generate a corresponding hash table;
the hash table generation module comprises:
the second character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset second character string conversion rule;
a second character string corresponding unit, configured to determine a character string of a start internet protocol address and a character string of an end internet protocol address corresponding to each area number;
the second sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding second ordered three-dimensional arrays according to corresponding sequencing results;
each line in the second ordered three-dimensional array stores one region number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the region number respectively;
the digital section conversion unit is used for converting each character string in the second ordered three-dimensional array into a corresponding digital section, wherein the digital section consists of four sections of numbers, and the number in each section is less than or equal to three digits;
the address index establishing unit is used for applying the digital field, generating at least one address index corresponding to each area number according to a preset index establishing rule and generating a hash table containing each index; the method comprises the following steps: selecting a region number as a current target region number;
and the step of acquiring the address index is executed: selecting a first appearing value and a segment with different appearance values in the starting internet protocol address or the ending internet protocol address from the left to the right in the digital segments corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, and determining the first appearing value and the segment with different appearance values as a target segment corresponding to the target area number; starting from the last-but-one section in the digital fields corresponding to the starting internet protocol address and the ending internet protocol address corresponding to the target area number, applying the target section to sequentially obtain all address indexes corresponding to the target area number;
updating the area number as the current target area number, and re-executing the step of obtaining the address index until obtaining at least one address index corresponding to each area number;
the preset index establishment rule comprises the following steps:
s1: judging whether the current segment of the starting internet protocol address and the current segment of the ending internet protocol address corresponding to the target area number are the target segments or not in a reverse order from the fourth segment;
if yes, go to step S2;
if not, and the third segment of the starting internet protocol address and the third segment of the ending internet protocol address corresponding to the target area number are the target segments, executing step S5;
if not, and the second segment of the starting internet protocol address and the second segment of the ending internet protocol address corresponding to the target area number are the target segments, executing step S13;
s2: judging whether the value of the current segment of the starting internet protocol address corresponding to the target area number is not equal to 0 and whether the value of the current segment of the ending internet protocol address is not equal to 255;
if the value of the current segment of the starting internet protocol address corresponding to the target area number is not 0 and the value of the current segment of the ending internet protocol address is not 255, executing S3;
if the value of the current segment of the starting internet protocol address corresponding to the target region number is 0 and the value of the current segment of the ending internet protocol address is equal to 255, executing S4;
s3: taking the four segments of Internet protocol address segments which are corresponding to all numerical values in the current segment of the starting Internet protocol address and the current segment of the ending Internet protocol address and contain all four segments corresponding to the current segment of the starting Internet protocol address and the ending Internet protocol address corresponding to the target area number as the Internet protocol address index of the current target area number;
s4: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address corresponding to the target area number, and taking the three segments of the remaining starting internet protocol address or the ending internet protocol address containing the first three segments as the internet protocol address index of the current target area number;
s5: judging the magnitude relation between the numerical value of the current segment of the starting internet protocol address corresponding to the target area number and the numerical value of the current segment of the ending internet protocol address and 0 and 255 respectively;
if the value of the current segment of the starting ip address corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment of the ending ip address corresponding to the target area number is not 255 and is not 0, then S6 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 0, and if the value of the current segment of the ending ip address corresponding to the target area number is 255, then S10 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 255 and if the value of the current segment of the ending ip address corresponding to the target area number is 255, then S11 is executed;
if the value of the current segment of the starting ip address corresponding to the target area number is 0, and if the value of the current segment of the ending ip address corresponding to the target area number is also 0, then S12 is executed;
s6: taking four segments of internet protocol address segments including all four segments corresponding to the values between the current value of the current segment of the starting internet protocol address corresponding to the target area number and 255 as a first internet protocol address index subgroup of the current target area number, and executing S7;
s7: taking four segments of internet protocol address segments including all four segments corresponding to the value between 0 and the current value of the current segment of the ending internet protocol address corresponding to the target area number as a second internet protocol address index subgroup of the current target area number, and then executing S8;
s8: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, adding 1 to the numerical value of the previous segment of the current segment of the starting internet protocol address corresponding to the target area number to obtain the corresponding starting three segments of internet protocol address segments containing the first to third segments, subtracting 1 from the numerical value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number to obtain the corresponding ending three segments of internet protocol address segments containing the first to third segments, taking all three segments of internet protocol address segments containing the starting three segments of internet protocol address segments to the ending three segments of internet protocol address segments as a third internet protocol address index subgroup of the current target area number, and then executing S9;
s9: forming an internet protocol address index corresponding to the current target area number by the first internet protocol address index subgroup, the second internet protocol address index subgroup and the third internet protocol address index subgroup in the S7-S8;
s10: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, generating a starting three-segment internet protocol address segment containing the first segment to the third segment of the starting internet protocol address, generating an ending three-segment internet protocol address segment containing the first segment to the third segment of the ending internet protocol address, and then taking all three internet protocol address segments containing the starting three-segment internet protocol address segment to the ending three-segment internet protocol address segment as the internet protocol address index of the current target area number;
s11: taking four segments of Internet protocol address segments corresponding to the current segment of the starting Internet protocol address as one of the Internet protocol address indexes of the current target area number, and deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, and adding 1 to the numerical value of the previous segment of the current segment of the initial internet protocol address corresponding to the target area number to obtain the corresponding initial three-segment internet protocol address segment containing the first segment to the third segment, and an ending three-segment Internet protocol address segment of the first segment to the third segment of the ending Internet protocol address corresponding to the target region number, then, all three Internet protocol address segments including the four Internet protocol address segments, the initial three Internet protocol address segments and the final three Internet protocol address segments are used as the Internet protocol address index of the current target area number;
s12: taking the four segments of Internet protocol address segments corresponding to the current segment in the ending Internet protocol address as one of the Internet protocol address indexes of the current target area number, and deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, and obtains a first three-segment internet protocol address segment including first to third segments corresponding to the first internet protocol address, and, subtracting 1 from the value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number, an ending three-segment internet protocol address segment of the first to third segments of the corresponding ending internet protocol address is obtained, then, all three Internet protocol address fields including the four Internet protocol address fields, the initial three Internet protocol address fields and the final three Internet protocol address fields are used as the Internet protocol address index of the current target area number;
s13: judging the magnitude relation between the numerical value of the current segment of the starting internet protocol address corresponding to the target area number and the numerical value of the current segment of the ending internet protocol address and 0 and 255 respectively;
if the value of the current segment of the starting ip address corresponding to the target area number is not 0 and is less than 255, and if the value of the current segment of the ending ip address corresponding to the target area number is not 255 and is not 0, then S14 is executed;
s14: taking four segments of internet protocol address segments including all four segments corresponding to the values between the current value of the current segment of the starting internet protocol address corresponding to the target area number and 255 as a first internet protocol address index subgroup of the current target area number, and executing S15;
s15: taking four segments of internet protocol address segments including all four segments corresponding to the value between 0 and the current value of the current segment of the ending internet protocol address corresponding to the target area number as a second internet protocol address index subgroup of the current target area number, and then executing S16;
s16: deleting the current segment of the starting internet protocol address and the current segment of the ending internet protocol address, adding 1 to the numerical value of the previous segment of the current segment of the starting internet protocol address corresponding to the target area number to obtain the corresponding starting three-segment internet protocol address segment containing the first to the third segments, subtracting 1 from the numerical value of the previous segment of the current segment of the ending internet protocol address corresponding to the target area number to obtain the corresponding ending three-segment internet protocol address segment containing the first to the third segments, and then combining the starting three-segment internet protocol address segment and the ending three-segment internet protocol address segment into a new starting internet protocol address and an ending internet protocol address, wherein the new starting internet protocol address and the ending internet protocol address only contain the contents of the first segment to the third segment, the contents of the foregoing steps S6 to S12 are then performed on the new start internet protocol address and the end internet protocol address.
8. The internet protocol address based geographic lookup system of claim 7 further comprising:
the system comprises an Internet protocol address acquisition module, a data processing module and a data processing module, wherein the Internet protocol address acquisition module is used for acquiring each area number and at least one Internet protocol address corresponding to each area number;
and the first ordered three-dimensional array generating module is used for generating a corresponding first ordered three-dimensional array by applying each region number and at least one internet protocol address corresponding to each region number.
9. The internet protocol address-based geographic lookup system of claim 8 wherein the first ordered three-dimensional array generation module comprises:
the first character string conversion unit is used for converting each Internet protocol address into a corresponding character string according to a preset first character string conversion rule;
a first character string corresponding unit, which is used for determining the character string of the starting internet protocol address and the character string of the ending internet protocol address corresponding to each area number;
the first sequencing unit is used for sequencing the character strings of the starting internet protocol addresses or the character strings of the ending internet protocol addresses according to the sequence of numerical values from small to large and generating corresponding first ordered three-dimensional arrays according to corresponding sequencing results;
and each line in the first ordered three-dimensional array stores one area number, a character string of a starting internet protocol address and a character string of an ending internet protocol address which correspond to the area number respectively.
10. The ip address-based geographic lookup apparatus of claim 9 wherein the first string conversion unit is further configured to:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit character string;
and deleting 0 which appears before the first non-0 digit in each twelve-bit character string which begins with 0 to obtain a character string which corresponds to each Internet protocol address.
11. The ip address-based geographic lookup apparatus of claim 7 wherein the second string conversion unit is further configured to:
adding 0 after the first separation point, and adding numbers between every two points in each internet protocol address into a three-digit number to obtain a twelve-bit string corresponding to each internet protocol address;
deleting each separation point in each twelve-bit string.
12. The ip address based lookup device of claim 11 wherein the field translation unit is further configured to perform the following:
dividing each twelve-bit string in the second ordered three-dimensional array into four segments, wherein each segment comprises three numbers;
and deleting 0 which appears before the first non-0 digit from the three-digit number beginning with 0 in each segment, and if all the segments which are 0 exist, reserving one 0 to obtain the digital field corresponding to each twelve-bit character string.
13. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the program performs the steps of the method for internet protocol address based locality search of any of claims 1 to 6.
14. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method for internet protocol address based locale searching according to any of the claims 1 to 6.
CN201910688369.9A 2019-07-29 2019-07-29 Area searching method and device based on internet protocol address Active CN110266834B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910688369.9A CN110266834B (en) 2019-07-29 2019-07-29 Area searching method and device based on internet protocol address

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910688369.9A CN110266834B (en) 2019-07-29 2019-07-29 Area searching method and device based on internet protocol address

Publications (2)

Publication Number Publication Date
CN110266834A CN110266834A (en) 2019-09-20
CN110266834B true CN110266834B (en) 2022-08-26

Family

ID=67912341

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910688369.9A Active CN110266834B (en) 2019-07-29 2019-07-29 Area searching method and device based on internet protocol address

Country Status (1)

Country Link
CN (1) CN110266834B (en)

Families Citing this family (2)

* 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
CN117278521B (en) * 2023-11-16 2024-03-19 烽台科技(北京)有限公司 Asset identification method and computer device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104796437A (en) * 2014-01-16 2015-07-22 深圳市快播科技有限公司 Method, device and system for querying geographical location information based on Nginx
CN107613043A (en) * 2017-09-26 2018-01-19 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN107682466A (en) * 2017-09-26 2018-02-09 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN108712519A (en) * 2018-05-31 2018-10-26 康键信息技术(深圳)有限公司 Localization method, device and the storage medium of IP address

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110191416B (en) * 2013-03-15 2022-04-15 美国结构数据有限公司 Apparatus, system and method for analyzing movement of target entity

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104796437A (en) * 2014-01-16 2015-07-22 深圳市快播科技有限公司 Method, device and system for querying geographical location information based on Nginx
CN107613043A (en) * 2017-09-26 2018-01-19 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN107682466A (en) * 2017-09-26 2018-02-09 小草数语(北京)科技有限公司 The regional information searching method and its device of IP address
CN108712519A (en) * 2018-05-31 2018-10-26 康键信息技术(深圳)有限公司 Localization method, device and the storage medium of IP address

Also Published As

Publication number Publication date
CN110266834A (en) 2019-09-20

Similar Documents

Publication Publication Date Title
JP6594988B2 (en) Method and apparatus for processing address text
CN102246165B (en) Method and apparatus for representing and identifying feature descriptors utilizing a compressed histogram of gradients
CN108846753B (en) Method and apparatus for processing data
US20140278228A1 (en) Mapping uncertain geometries to graticules
US8838550B1 (en) Readable text-based compression of resource identifiers
CN112449009B (en) SVD-based communication compression method and device for Federal learning recommendation system
CN111553670B (en) Transaction processing method and device and computer readable storage medium
CN108733317B (en) Data storage method and device
CN110266834B (en) Area searching method and device based on internet protocol address
US20180285078A1 (en) Method and apparatus for generating random character string
CN111369247A (en) Cross-bank transaction data processing method and device
US9602129B2 (en) Compactly storing geodetic points
KR20090097057A (en) Method for coding and decoding connectivity of 3d data implemented as mesh model
CN114818000A (en) Privacy protection set confusion intersection method, system and related equipment
CN109302449B (en) Data writing method, data reading device and server
CN114153856A (en) Host data double-writing method and device
CN113935069B (en) Data verification method, device and equipment based on block chain and storage medium
CN105991400B (en) Group searching method and device
CN107943981A (en) HBase rows paging method, server and computer-readable recording medium
CN110545107B (en) Data processing method and device, electronic equipment and computer readable storage medium
CN113094454A (en) Map data searching method and device
CN113157695B (en) Data processing method and device, readable medium and electronic equipment
CN111179376B (en) Method and device for generating flow node diagram, storage medium and electronic equipment
CN110727442B (en) Data storage optimization method and system for embedded platform
CN113849705A (en) Mass data retrieval method, system and storage medium

Legal Events

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