CN108712519B - Method and device for positioning IP address and storage medium - Google Patents

Method and device for positioning IP address and storage medium Download PDF

Info

Publication number
CN108712519B
CN108712519B CN201810547509.6A CN201810547509A CN108712519B CN 108712519 B CN108712519 B CN 108712519B CN 201810547509 A CN201810547509 A CN 201810547509A CN 108712519 B CN108712519 B CN 108712519B
Authority
CN
China
Prior art keywords
address
digital address
target
digital
value
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
CN201810547509.6A
Other languages
Chinese (zh)
Other versions
CN108712519A (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.)
Kangjian Information Technology Shenzhen Co Ltd
Original Assignee
Kangjian Information Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Kangjian Information Technology Shenzhen Co Ltd filed Critical Kangjian Information Technology Shenzhen Co Ltd
Priority to CN201810547509.6A priority Critical patent/CN108712519B/en
Publication of CN108712519A publication Critical patent/CN108712519A/en
Application granted granted Critical
Publication of CN108712519B publication Critical patent/CN108712519B/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
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The invention provides a method for positioning an IP address, which comprises the following steps: receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule; reading a median value of a predetermined positioning array and a starting value and an ending value of a digital address field corresponding to the median value, and judging whether the target IP address meets the condition of geographic position information positioned in the digital address field corresponding to the median value or not according to the target digital address; if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or if the condition is not met, determining a new positioning array according to the starting value and the ending value of the digital address field corresponding to the median, and returning to execute the reading step. The invention also provides an electronic device and a computer storage medium. By using the method and the device, the real geographical position information of the target IP address can be quickly determined.

Description

Method and device for positioning IP address and storage medium
Technical Field
The present invention relates to the field of Internet technologies, and in particular, to a method for locating an IP (Internet Protocol), an electronic device, and a computer-readable storage medium.
Background
The internet is often referred to as a virtual world, and various nodes (e.g., hosts or routers) in the internet exist physically and must be stored with a particular geographic location. Finding the geographical location information of a node on the internet is a frequent matter to do.
For example, in the precise placement of internet advertisements, regional targeting is a widely used targeting condition, and IP parsing and positioning are required for almost every request. Particularly for a highly concurrent advertisement system with large traffic, the QPS (request/second) reaches tens of thousands, and the time of regional targeting directly affects the user experience. Therefore, it is an important part of internet advertising to solve the problem of IP geographical location. In order to improve user experience, the current general practice is: the addition of the server enhances the advertisement processing capacity of the server, uses a cache reduction request, avoids IP resolution by storing user information through redis, or carries out segmented query on an IP address library, or carries out real-time query on a third party, and the like, and the processing time is usually 3-100 milliseconds. If the QPS is not very large, the user experience can be improved to some extent, but when the QPS is concurrent to tens of thousands or more than a hundred thousand, the above popular scheme cannot solve the user experience.
Disclosure of Invention
In view of the above, the present invention provides a method, a server and a computer readable storage medium for locating an IP address, which mainly aims to determine the real geographical location information of a target IP address quickly and accurately.
In order to achieve the above object, the present invention provides a method for positioning an IP address, including:
s1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
s2, reading the median of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median;
s3, judging whether the target IP address meets the condition of the geographic position information of the digital address field corresponding to the median value according to the target digital address;
s4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or
And S5, if the condition is not met, determining a new positioning array according to the start value and the end value of the digital address field corresponding to the median value, and returning to execute the step S2.
In addition, the present invention also provides an electronic device, characterized in that the device comprises: the storage is stored with a positioning program of an IP address which can run on the processor, and when the positioning program of the IP address is executed by the processor, the following steps can be realized:
a1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
a2, reading the median value of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median value;
a3, judging whether the target IP address meets the condition of locating the geographic position information of the digital address field corresponding to the median value according to the target digital address;
a4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or
And A5, if the condition is not met, determining a new positioning array according to the start value and the end value of the digital address field corresponding to the median, and returning to execute the step A2.
In addition, to achieve the above object, the present invention further provides a computer-readable storage medium, where the computer-readable storage medium includes a positioning program for an IP address, and when the positioning program for the IP address is executed by a processor, any step in the positioning method for the IP address can be implemented.
The invention provides a positioning method of an IP address, an electronic device and a computer readable storage medium, wherein a digital address information base, namely a positioning array, is established by utilizing the geographical position information of a known IP address, and the geographical position information of the target IP address is determined by determining the digital address of the target IP address to be positioned and the digital address segment to which the digital address belongs and further determining the geographical position information of the digital address segment through the positioning array, so that the geographical position information of the target IP address is determined, and the real geographical position information of the target IP address is rapidly and accurately determined; and then determining one or more pieces of reference geographic position information according to the user behavior data of the terminal bound by the IP address, taking the geographic position information determined according to the positioning array contained in the reference geographic position information as a geographic position positioning result of the target IP address, and further verifying the positioning result, so that the positioning accuracy of the target IP address is improved.
Drawings
FIG. 1 is a flowchart illustrating a method for locating an IP address according to a preferred embodiment of the present invention;
FIG. 2 is a diagram of an electronic device according to a preferred embodiment of the present invention;
fig. 3 is a schematic diagram of program modules of the positioning procedure of the IP address in fig. 2.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The invention provides a method for positioning an IP address. Referring to fig. 1, a flow chart of a preferred embodiment of the method for locating an IP address of the present invention is shown. The method may be performed by an apparatus, which may be implemented by software and/or hardware.
In the present embodiment, the method for locating an IP address includes steps S1-S5:
s1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
an Internet Protocol (IP) address is represented by "dotted decimal" and is divided into 4 parts by "-"; the numeric address is a string of numbers represented in "decimal".
And after receiving the positioning request, acquiring the IP address to be positioned in the positioning request as a target IP address, and executing conversion operation on the target IP address.
Specifically, the preset conversion rule is to convert the target IP address into a numeric address, and the conversion formula is:
IPZ=A*256^3+B*256^2+C*256+D
wherein, IPZA, B, C, D sequentially represents a first portion, a second portion, a third portion, and a fourth portion of the destination IP address for the destination numeric address.
For example: the conversion of a hundred degree IP address of "119.75.218.77" to a numeric address is "2001459789".
S2, reading the median of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median;
s3, judging whether the target IP address meets the condition of the geographic position information of the digital address field corresponding to the median value according to the target digital address;
wherein the predetermined positioning array comprises: the digital address fields corresponding to different IP address fields and the geographic position information corresponding to each digital address field.
Specifically, the positioning array is obtained by the following steps:
acquiring an IP address field set corresponding to a designated area, respectively acquiring a starting IP address and an ending IP address corresponding to the IP address field, respectively converting the starting IP address and the ending IP address into a starting digital address and an ending digital address according to a preset conversion rule, and determining a digital address field set corresponding to the IP address field set; and
and sequencing the digital address fields in the digital address field set according to the sequence from small to large, and simultaneously sequentially storing the digital address fields corresponding to the IP address fields and the corresponding geographic position information in an array to determine a positioning array.
In this embodiment, each IP address segment is represented by a set formed by a start address and an end address corresponding to a start IP address and an end IP address of each IP address segment, respectively, to obtain a set of digital address segments. Wherein, the conversion rule is consistent with the above steps, which is not described herein again.
And performing integer conversion on each IP address section corresponding to the designated area to obtain a digital address section set C corresponding to the IP address section set { Ai (Ai, bi) … }, then performing ascending sequencing on the digital address sections in the set C, and sequentially storing the sequenced IP address sections in the Array.
Specifically, Array is [ a1(a1, b1), a2(a2, b2), … Ai (Ai, bi) ], where Array is a positioning Array, Ai represents a certain geographic location, Ai represents a start value of an IP address segment corresponding to the geographic location, and bi represents an end value of the IP address segment corresponding to the geographic location.
It should be noted that, in the IP address field set, the IP address fields are not consecutive, that is, there is a gap between two adjacent IP address fields, and similarly, there is a gap between the number address field set.
It can be understood that whether the IP address field of the designated area is comprehensive or not directly affects the location of the subsequent target IP address. Therefore, the acquisition of the IP address field of the designated area is crucial. Under an ideal state, all IP address fields of nationwide or even global cities are obtained, all the IP address fields are converted, and a complete positioning array is further determined.
For example, the geographic location information corresponding to each IP address segment is obtained by analyzing geographic location information of a plurality of known IP addresses, and specifically includes: obtaining geographical location information corresponding to a plurality of known IP addresses; dividing a plurality of IP address segments according to the distribution condition of a plurality of known IP addresses in a network address space and the geographical location information corresponding to the known IP addresses respectively, and determining the geographical location information corresponding to each IP address segment.
The geographic location information for the known IP address may be obtained in various ways, such as, for example, network user resource submission, network service provider submission, and the like. In the following embodiments, two ways of obtaining geographical location information of a known IP by analyzing a user on the internet with a mobile phone and obtaining location information of the known IP by analyzing a user registered on the internet are given, but the present invention includes, but is not limited to, the two ways.
For example, obtaining geographic location information corresponding to each of a plurality of known IP addresses specifically includes: obtaining IP addresses of a plurality of mobile network users when surfing the Internet and the local number of each mobile network user; searching the physical attribution of the local number of each mobile network user; and taking the physical attribution of the local number of each mobile network user as the geographic position information corresponding to the IP address when the mobile network user accesses the Internet. In the embodiment, the mobile phone number is used for determining the IP location of the known IP, so that the geographic position information of the IP section to which the mobile phone number belongs is determined.
For another example, obtaining geographic location information corresponding to each of a plurality of known IP addresses specifically includes: obtaining IP addresses of a plurality of users when surfing the Internet and online registration information of each user; acquiring the geographical location information of the user from the online registration information; and taking the obtained geographical position information of each user as the geographical position information corresponding to the IP address when the user accesses the Internet. For example, the portal SOHU has tens of millions of registered users, and the geographic location information of some users can be determined through the registered information of some users (such as geographic location information or mobile phone numbers or fixed phones with area codes, etc. directly registered by the users themselves). Because of the huge number of registered users, the established IP section information base can basically cover each IP section.
Of course, the above two methods may have certain noises, for example, a registered user in Shanghai may surf the Internet in Beijing, or a user may take a registered mobile phone in Shanghai to use the mobile phone in Beijing (for example, surf the Internet). Noise removal is also required to obtain more accurate information.
For example, after obtaining the geographic location information corresponding to each of a plurality of known IP addresses, the method further includes: performing probability analysis on geographical location information of a part of continuous multiple known IP addresses; IP addresses where the geographical location information is not the most probable are excluded. For example, a-H represents n IPs, with IP addresses increasing from a to H. Wherein m places such as D, E are not in the P place, and the rest n-m IPs such as A, B, C, H are in the same place and are in the P place. If m/n < 1 over the entire IP section, then this m point is noise.
Those skilled in the art will understand that the above denoising scheme can make the created IP segment information base more accurate. However, if there is no noise in the collected information itself, or the accuracy requirements for the geographical location information are not particularly high, then even a small portion of the noise is allowed (just possibly dividing the located IP fields more sparsely).
After converting the target IP address to be positioned into a target digital address, acquiring a median of the positioning array, namely a digital address segment corresponding to the median in the sequenced digital address segments, and reading a starting value (a starting digital address) and an ending value (an ending digital address) of the digital address segment. And judging whether the target IP address meets the condition of positioning the geographic position information of the digital address segment corresponding to the median value or not according to the relation between the target digital address and the initial value and the end value of the digital address segment.
Specifically, when the value of the target digital address is greater than or equal to the start value of the digital address field corresponding to the median value and less than or equal to the end value of the digital address field corresponding to the median value, it is determined that the target digital address satisfies the condition of locating the geographic location information of the digital address field corresponding to the median value, that is, the target IP address satisfies the condition of locating the geographic location information of the IP address field corresponding to the digital address field; otherwise, judging that the target IP address does not meet the condition of the geographic position information positioned in the digital address field corresponding to the median.
S4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median;
and S5, if the condition is not met, determining a new positioning array according to the starting value and the ending value of the digital address field corresponding to the median, and returning to execute the step S2.
And when the target IP address meets the condition of positioning the geographic position information of the digital address field corresponding to the median value, reading the geographic position information of the digital address field corresponding to the median value from the positioning array as the geographic position positioning result of the target IP address field. And generating prompt information according to the geographic position positioning result and displaying the prompt information, for example, feeding back a positioning result to a terminal sending an IP address positioning request and displaying the positioning result.
When the target IP address does not meet the condition of the geographical position information of the digital address field corresponding to the median value, the sub-positioning array corresponding to the positioning array needs to be further found out. Specifically, the step of determining a new location array according to the start value and the end value of the digital address field corresponding to the median value includes:
when the target digital address is smaller than the initial value of the digital address segment corresponding to the median, taking a digital address segment set smaller than the initial value of the digital address segment corresponding to the median in the positioning array as a first new positioning array; or
And when the target digital address is larger than the initial value of the digital address segment corresponding to the median, taking the digital address segment set which is larger than the end value of the digital address segment corresponding to the median in the positioning array as a second new positioning array.
That is, if the target digital address falls to the left of the median digital address field in the positioning array, the left portion of the median digital address field in the positioning array is used as the first new positioning array, and if the target digital address falls to the right of the median digital address field in the positioning array, the right portion of the median digital address field in the positioning array is used as the second new positioning array, and the first new/second new positioning array is used as the predetermined positioning array in step S2. Then, the median reading step and the judging step in the subsequent steps are continuously executed.
With this step, the search area of the set of digital address segments C is gradually reduced until a digital address segment covering the target digital address is found.
If the chinese IP address field has 10000000 address fields, find a geographic location information of IP ═ a0.b0.c0.d0. The number of times Sn log2(10^7) 24 is needed to query the geographical location information of the IP, that is, the most pessimistic positioning needs 24 times. However, the operation level of the integer belongs to nanoseconds. Therefore, the performance of the algorithm belongs to the microsecond level, namely, million-level query can be realized in a single thread of the algorithm every second, and the efficiency of IP address positioning is greatly improved.
However, when the digital address field covering the target digital address does not exist in the digital address field set C, it indicates that the data address field corresponding to the target digital address cannot be determined, and further the target IP address cannot be located, and sends out the first warning information to prompt that the target IP address cannot be located, until the query is finished.
The reason for this may be that the IP address field corresponding to the pre-acquired designated area is not complete enough, for example, the designated area only contains the chinese IP address, and when the terminal sends the request in the united states, the number address field set C does not contain the number address corresponding to the U.S IP address, so that the corresponding IP address field and location cannot be determined. Thus, in addition to prompting the inability to locate, a prompt is also required to update the set of numerical address segments C. In the ideal state, this is not the case, and therefore, the description thereof is omitted.
In the method for locating an IP address provided in the above embodiment, a digital address information base, that is, a locating array, is established by using known geographical location information of an accurate IP address, a target IP address to be located is converted into a digital address, a digital address segment to which the digital address belongs is determined, and then geographical location information of the digital address segment is determined by using the locating array, so that the geographical location information of the target IP address is determined, and the problem of too low query accuracy in the prior art is solved, so that accurate geographical location information can be queried; meanwhile, in the inquiry process, the median of the digital address is compared and judged with the median object every time, so that the inquiry time can be greatly reduced, and the real geographic position information of the target IP address can be quickly and accurately determined.
The present invention provides another preferred embodiment of the method for locating an IP address based on the above embodiments.
In other embodiments, the method includes steps S1-S6, wherein steps S1-S5 are substantially the same as the above embodiments and are not repeated herein. With the difference that the step S6 includes:
acquiring user behavior data from the terminal equipment associated with the target IP address, and determining one or more pieces of reference geographical position information according to the user behavior data;
when the one or more pieces of reference geographic position information contain geographic position information of the digital address field corresponding to the median value, determining the geographic position information of the digital address field corresponding to the median value as a geographic position positioning result of the target IP address; and
and when the one or more pieces of geographical location information do not contain the geographical location information of the digital address field corresponding to the median, generating second early warning information and prompting that the positioning fails.
Wherein the user behavior data comprises: at least one of Global Positioning System (GPS) data, map access data, location search data, and weather inquiry data for a preset time.
The user behavior data may also be location-related setting data that the user autonomously sets in the relevant application on the terminal device associated with the IP address. For example, in the case where a user logs in a microblog or personal area network application on a terminal device associated with an IP address, visible location data set by the user when the user releases the status, or location data in personal data set in advance when the user logs in a chat application on the device.
It should be noted that, since the reliability of the setting data related to the location, which is autonomously set by the user in the relevant application on the device associated with the IP address, is low due to the fact that many users protect the privacy of the users, the reliability is low although the geographical location information corresponding to the IP address can be identified by using the setting data related to the location as the user behavior data; the GPS data, the map access data, the position search data and the weather query data can actually reflect the user requirements generally, so that at least one of the GPS data, the map access data, the position search data and the weather query data is used as the user behavior data, and the reliability of the reference geographic position information corresponding to the identified IP address is high.
In addition, the closer the time corresponding to the acquired user behavior data is to the current time, the closer the reference geographical location information corresponding to the acquired user behavior data is to the actual location.
And when the reference address position information contains the geographic position information corresponding to the digital address field corresponding to the median, determining the geographic position information of the digital address field corresponding to the median as a geographic position positioning result of the target IP address, and further verifying the accuracy of IP address positioning by utilizing the step.
It should be noted that an IP address field (i.e. a continuous IP address) belongs to a region for a period of time, that is, an IP address field originally belonging to the area a may belong to the area B after a certain period of time. Therefore, when the reference address location information does not include the geographic location information corresponding to the digital address field corresponding to the median, the geographic location information corresponding to the IP address field may have changed, and therefore, second warning information needs to be generated to prompt the update of the digital address set C in the positioning array.
In the method for locating an IP address provided in the above embodiment, a digital address information base, that is, a locating array, is established by using geographic location information of a known IP address, and geographic location information of a target IP address is determined by determining a digital address of the target IP address to be located and a digital address segment to which the digital address belongs, and further determining the geographic location information of the digital address segment by using the locating array, so that the geographic location information of the target IP address is determined, and real geographic location information of the target IP address is determined quickly and accurately; and then determining one or more pieces of reference geographic position information according to the user behavior data of the terminal bound by the IP address, taking the geographic position information determined according to the positioning array contained in the reference geographic position information as a geographic position positioning result of the target IP address, and further verifying the positioning result, so that the positioning accuracy of the target IP address is improved.
The invention also provides an electronic device. Fig. 2 is a schematic diagram of an electronic device 1 according to a preferred embodiment of the invention.
In this embodiment, the electronic device 1 may be a server, a smart phone, a tablet computer, a portable computer, a desktop computer, or other terminal equipment with a data processing function, where the server may be a rack server, a blade server, a tower server, or a cabinet server.
The electronic device 1 includes a memory 11, a processor 12, a communication bus 13, and a network interface 14.
The memory 11 includes at least one type of readable storage medium, which includes a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 11 may in some embodiments be an internal storage unit of the electronic device 1, such as a hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic apparatus 1 in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic apparatus 1. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic apparatus 1.
The memory 11 may be used not only to store application software installed in the electronic device 1 and various types of data, such as the positioning program 10 of the IP address, but also to temporarily store data that has been output or will be output.
The processor 12 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor or other data Processing chip in some embodiments, and is used for executing program codes stored in the memory 11 or Processing data, such as the positioning program 10 of the IP address.
The communication bus 13 is used to realize connection communication between these components.
The network interface 14 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface), and is typically used to establish a communication link between the electronic apparatus 1 and other electronic devices.
Fig. 2 only shows the electronic device 1 with components 11-14, and it will be understood by a person skilled in the art that the structure shown in fig. 2 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than shown, or a combination of certain components, or a different arrangement of components.
Optionally, the electronic device 1 may further comprise a user interface, the user interface may comprise a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface may further comprise a standard wired interface, a wireless interface.
Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an Organic Light-Emitting Diode (OLED) touch screen, or the like. The display, which may also be referred to as a display screen or display unit, is used for displaying information processed in the electronic apparatus 1 and for displaying a visualized user interface.
In the embodiment of the electronic device 1 shown in fig. 2, the program code of the positioning program 10 of the IP address is stored in the memory 11 as a kind of computer storage medium, and when the processor 12 executes the program code of the positioning program 10 of the IP address, the following steps are implemented:
a1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
an Internet Protocol (IP) address is represented by "dotted decimal" and is divided into 4 parts by "-"; the numeric address is a string of numbers represented in "decimal".
And after receiving the positioning request, acquiring the IP address to be positioned in the positioning request as a target IP address, and executing conversion operation on the target IP address.
Specifically, the preset conversion rule is to convert the target IP address into a numeric address, and the conversion formula is:
IPZ=A*256^3+B*256^2+C*256+D
wherein, IPZA, B, C, D sequentially represents a first portion, a second portion, a third portion, and a fourth portion of the destination IP address for the destination numeric address.
For example: the conversion of a hundred degree IP address of "119.75.218.77" to a numeric address is "2001459789".
A2, reading the median value of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median value;
a3, according to the target digital address, judging whether the target IP address meets the condition of the geographic position information of the digital address field corresponding to the median;
wherein the predetermined positioning array comprises: the digital address fields corresponding to different IP address fields and the geographic position information corresponding to each digital address field.
Specifically, the positioning array is obtained by the following steps:
acquiring an IP address field set corresponding to a designated area, respectively acquiring a starting IP address and an ending IP address corresponding to the IP address field, respectively converting the starting IP address and the ending IP address into a starting digital address and an ending digital address according to a preset conversion rule, and determining a digital address field set corresponding to the IP address field set; and
and sequencing the digital address fields in the digital address field set according to the sequence from small to large, and simultaneously sequentially storing the digital address fields corresponding to the IP address fields and the corresponding geographic position information in an array to determine a positioning array.
In this embodiment, each IP address segment is represented by a set formed by a start address and an end address corresponding to a start IP address and an end IP address of each IP address segment, respectively, to obtain a set of digital address segments. Wherein, the conversion rule is consistent with the above steps, which is not described herein again.
And performing integer conversion on each IP address section corresponding to the designated area to obtain a digital address section set C corresponding to the IP address section set { Ai (Ai, bi) … }, then performing ascending sequencing on the digital address sections in the set C, and sequentially storing the sequenced IP address sections in the Array.
Specifically, Array is [ a1(a1, b1), a2(a2, b2), … Ai (Ai, bi) ], where Array is a positioning Array, Ai represents a certain geographic location, Ai represents a start value of an IP address segment corresponding to the geographic location, and bi represents an end value of the IP address segment corresponding to the geographic location.
It should be noted that, in the IP address field set, the IP address fields are not consecutive, that is, there is a gap between two adjacent IP address fields, and similarly, there is a gap between the number address field set.
It can be understood that whether the IP address field of the designated area is comprehensive or not directly affects the location of the subsequent target IP address. Therefore, acquisition of an IP address field of a specified area is crucial. Under an ideal state, all IP address fields of nationwide or even global cities are obtained, all the IP address fields are converted, and a complete positioning array is further determined.
For example, the geographic location information corresponding to each IP address segment is obtained by analyzing geographic location information of a plurality of known IP addresses, and specifically includes: obtaining geographical location information corresponding to a plurality of known IP addresses; dividing a plurality of IP address segments according to the distribution condition of a plurality of known IP addresses in a network address space and the geographical location information corresponding to the known IP addresses respectively, and determining the geographical location information corresponding to each IP address segment.
The geographic location information for the known IP address may be obtained in various ways, such as, for example, network user resource submission, network service provider submission, and the like. In the following embodiments, two ways of obtaining geographical location information of a known IP by analyzing a user on the internet with a mobile phone and obtaining location information of the known IP by analyzing a user registered on the internet are given, but the present invention includes, but is not limited to, the two ways.
For example, obtaining geographic location information corresponding to each of a plurality of known IP addresses specifically includes: obtaining IP addresses of a plurality of mobile network users when surfing the Internet and the local number of each mobile network user; searching the physical attribution of the local number of each mobile network user; and taking the physical attribution of the local number of each mobile network user as the geographic position information corresponding to the IP address when the mobile network user accesses the Internet. In the embodiment, the mobile phone number is used for determining the IP location of the known IP, so that the geographic position information of the IP section to which the mobile phone number belongs is determined.
For another example, obtaining geographic location information corresponding to each of a plurality of known IP addresses specifically includes: obtaining IP addresses of a plurality of users when surfing the Internet and online registration information of each user; acquiring the geographical location information of the user from the online registration information; and taking the obtained geographical position information of each user as the geographical position information corresponding to the IP address when the user accesses the Internet. For example, the portal SOHU has tens of millions of registered users, and the geographic location information of some users can be determined through the registered information of some users (such as geographic location information or mobile phone numbers or fixed phones with area codes, etc. directly registered by the users themselves). Because of the huge number of registered users, the established IP section information base can basically cover each IP section.
Of course, the above two methods may have certain noises, for example, a registered user in Shanghai may surf the Internet in Beijing, or a user may take a registered mobile phone in Shanghai to use the mobile phone in Beijing (for example, surf the Internet). Noise removal is also required to obtain more accurate information.
For example, after obtaining the geographic location information corresponding to each of a plurality of known IP addresses, the method further includes: performing probability analysis on geographical location information of a part of continuous multiple known IP addresses; IP addresses where the geographical location information is not the most probable are excluded. For example, a-H represents n IPs, with IP addresses increasing from a to H. Wherein m places such as D, E are not in the P place, and the rest n-m IPs such as A, B, C, H are in the same place and are in the P place. If m/n < 1 over the entire IP section, then this m point is noise.
Those skilled in the art will understand that the above denoising scheme can make the created IP segment information base more accurate. However, if there is no noise in the collected information itself, or the accuracy requirements for the geographical location information are not particularly high, then even a small portion of the noise is allowed (just possibly dividing the located IP fields more sparsely).
After converting the target IP address to be positioned into a target digital address, acquiring a median of the positioning array, namely a digital address segment corresponding to the median in the sequenced digital address segments, and reading a starting value (a starting digital address) and an ending value (an ending digital address) of the digital address segment. And judging whether the target IP address meets the condition of positioning the geographic position information of the digital address segment corresponding to the median value or not according to the relation between the target digital address and the initial value and the end value of the digital address segment.
Specifically, when the value of the target digital address is greater than or equal to the start value of the digital address field corresponding to the median value and less than or equal to the end value of the digital address field corresponding to the median value, it is determined that the target digital address satisfies the condition of locating the geographic location information of the digital address field corresponding to the median value, that is, the target IP address satisfies the condition of locating the geographic location information of the IP address field corresponding to the digital address field; otherwise, judging that the target IP address does not meet the condition of the geographic position information positioned in the digital address field corresponding to the median.
A4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median;
and A5, if the condition is not met, determining a new positioning array according to the start value and the end value of the digital address field corresponding to the median, and returning to execute the step A2.
And when the target IP address meets the condition of positioning the geographic position information of the digital address field corresponding to the median value, reading the geographic position information of the digital address field corresponding to the median value from the positioning array as the geographic position positioning result of the target IP address field. And generating prompt information according to the geographic position positioning result and displaying the prompt information, for example, feeding back a positioning result to a terminal sending an IP address positioning request and displaying the positioning result.
When the target IP address does not meet the condition of the geographic position information positioned in the digital address field corresponding to the median value, a sub-positioning array corresponding to the positioning array needs to be further found out. Specifically, the step of determining a new location array according to the start value and the end value of the digital address field corresponding to the median value includes:
when the target digital address is smaller than the initial value of the digital address segment corresponding to the median, taking a digital address segment set smaller than the initial value of the digital address segment corresponding to the median in the positioning array as a first new positioning array; or
And when the target digital address is larger than the initial value of the digital address segment corresponding to the median, taking the digital address segment set which is larger than the end value of the digital address segment corresponding to the median in the positioning array as a second new positioning array.
That is, if the target digital address falls to the left of the median digital address field in the positioning array, the left portion of the median digital address field in the positioning array is used as the first new positioning array, and if the target digital address falls to the right of the median digital address field in the positioning array, the right portion of the median digital address field in the positioning array is used as the second new positioning array, and the first new/second new positioning array is used as the predetermined positioning array in step a 2. Then, the median reading step and the judging step in the subsequent steps are continuously executed.
With this step, the search area of the set of digital address segments C is gradually reduced until a digital address segment covering the target digital address is found.
If the chinese IP address field has 10000000 address fields, find a geographic location information of IP ═ a0.b0.c0.d0. The number of times Sn log2(10^7) 24 is needed to query the geographical location information of the IP, that is, the most pessimistic positioning needs 24 times. However, the operation level of the integer belongs to nanoseconds. Therefore, the performance of the algorithm belongs to the microsecond level, namely, million-level query can be realized in a single thread of the algorithm every second, and the efficiency of IP address positioning is greatly improved.
However, when the digital address field covering the target digital address does not exist in the digital address field set C, it indicates that the data address field corresponding to the target digital address cannot be determined, and further the target IP address cannot be located, and sends out the first warning information to prompt that the target IP address cannot be located, until the query is finished.
The reason for this may be that the IP address field corresponding to the pre-acquired designated area is not complete enough, for example, the designated area only contains the chinese IP address, and when the terminal sends the request in the united states, the number address field set C does not contain the number address corresponding to the U.S IP address, so that the corresponding IP address field and location cannot be determined. Thus, in addition to prompting the inability to locate, a prompt is also required to update the set of numerical address segments C. In the ideal state, this is not the case, and therefore, the description thereof is omitted.
In the electronic device 1 proposed in the above embodiment, a digital address information base, that is, a positioning array, is established by using the known geographical location information with accurate IP addresses, a target IP address to be positioned is converted into a digital address, a digital address segment to which the digital address belongs is determined, and then the geographical location information of the digital address segment is determined by using the positioning array, so that the geographical location information of the target IP address is determined, and the problem that the query accuracy is too low in the prior art is solved, so that accurate geographical location information can be queried; meanwhile, in the inquiry process, the median of the digital address is compared and judged with the median object every time, so that the inquiry time can be greatly reduced, and the real geographic position information of the target IP address can be quickly and accurately determined.
Alternatively, in other embodiments, the IP address location program 10 may be divided into one or more modules, and one or more modules are stored in the memory 11 and executed by one or more processors (in this embodiment, the processor 12) to implement the present invention, where a module refers to a series of computer program instruction segments capable of performing a specific function. For example, referring to fig. 3, which is a schematic block diagram of the positioning program 10 of the IP address in fig. 2, in this embodiment, the positioning program 10 of the IP address may be divided into a conversion module 110, a reading module 120, a determination module 130, a positioning module 140 and a sub-positioning array determination module 150, the functions or operation steps implemented by the modules 110 and 150 are similar to those described above, and are not described in detail here, for example, wherein:
the conversion module 110 is configured to receive a positioning request carrying a target IP address, and convert the target IP address into a target digital address according to a preset conversion rule;
a reading module 120, configured to read a median value of a predetermined positioning array and a start value and an end value of a digital address segment corresponding to the median value;
a judging module 130, configured to judge, according to the target digital address, whether the target IP address meets a condition of locating geographic location information of a digital address segment corresponding to the median;
a positioning module 140, configured to determine, if a condition is met, a geographic position positioning result of the target IP address according to the geographic position information of the digital address segment corresponding to the median; or
And a new positioning array determining module 150, configured to determine a new positioning array according to the start value and the end value of the digital address segment corresponding to the median if the condition is not met, and then return to performing the reading step.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium includes a positioning program 10 of an IP address, and when executed by a processor, the positioning program 10 of the IP address implements the following operations:
a1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
a2, reading the median value of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median value;
a3, judging whether the target IP address meets the condition of locating the geographic position information of the digital address field corresponding to the median value according to the target digital address;
a4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or
And A5, if the condition is not met, determining a new positioning array according to the start value and the end value of the digital address field corresponding to the median, and returning to execute the step A2.
The specific implementation of the computer readable storage medium of the present invention is substantially the same as the specific implementation of the above-mentioned method for locating an IP address, and will not be described herein again.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that includes the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for positioning an IP address is applied to an electronic device, and is characterized in that the method comprises the following steps:
s1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
s2, reading the median value of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median value, wherein the predetermined positioning array is obtained by the following steps:
acquiring an IP address field set corresponding to a designated area, performing probability analysis on geographical location information of a plurality of continuous IP addresses, and excluding IP addresses of which the geographical location information is not the highest in probability; respectively acquiring a starting IP address and an ending IP address corresponding to the IP address field, respectively converting the starting IP address and the ending IP address into a starting digital address and an ending digital address according to a preset conversion rule, and determining a digital address field set corresponding to the IP address field set; sequencing all the digital address fields in the digital address field set according to the sequence from small to large, and simultaneously sequentially storing the digital address fields corresponding to all the IP address fields and the corresponding geographic position information in an array to determine a positioning array;
s3, judging whether the target IP address meets the condition of the geographic position information of the digital address field corresponding to the median value according to the target digital address;
s4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or
And S5, if the condition is not met, determining a new positioning array according to the starting value and the ending value of the digital address field corresponding to the median, and returning to execute the step S2.
2. The method according to claim 1, wherein the step of determining whether the target IP address satisfies the condition for locating the geographic location information of the numeric address segment corresponding to the median value comprises:
and when the value of the target digital address is greater than or equal to the starting value of the digital address field corresponding to the median value and less than or equal to the ending value of the digital address field corresponding to the median value, judging that the target digital address meets the condition of locating the geographic position information of the digital address field corresponding to the median value, and the target IP address meets the condition of locating the geographic position information of the digital address field.
3. The method of claim 2, wherein the step of determining a new location array according to the start value and the end value of the numeric address segment corresponding to the median value comprises:
when the target digital address is smaller than the initial value of the digital address segment corresponding to the median, taking a digital address segment set smaller than the initial value of the digital address segment corresponding to the median in the positioning array as a first new positioning array; or
And when the target digital address is larger than the end value of the digital address field corresponding to the median, taking the digital address field set larger than the end value of the digital address field corresponding to the median in the positioning array as a second new positioning array.
4. The method of claim 3, further comprising:
generating prompt information according to the geographic position positioning result and displaying the prompt information; and
and when the digital address field containing the target digital address does not exist in the positioning array, generating first early warning information and prompting that the positioning fails.
5. The method for locating an IP address according to any one of claims 1 to 4, further comprising the steps of:
acquiring user behavior data from the terminal equipment associated with the target IP address, and determining one or more pieces of reference geographical position information according to the user behavior data;
when the one or more pieces of reference geographic position information contain geographic position information of the digital address field corresponding to the median value, determining the geographic position information of the digital address field corresponding to the median value as a geographic position positioning result of the target IP address; and
and when the one or more pieces of geographical location information do not contain the geographical location information of the digital address field corresponding to the median, generating second early warning information and prompting that the positioning fails.
6. An electronic device, comprising: the storage is stored with a positioning program of an IP address which can run on the processor, and when the positioning program of the IP address is executed by the processor, the following steps can be realized:
a1, receiving a positioning request carrying a target IP address, and converting the target IP address into a target digital address according to a preset conversion rule;
a2, reading the median value of the predetermined positioning array and the start value and the end value of the digital address field corresponding to the median value, wherein the predetermined positioning array is obtained by the following steps:
acquiring an IP address field set corresponding to a designated area, performing probability analysis on geographical location information of a plurality of continuous IP addresses, and excluding IP addresses of which the geographical location information is not the highest in probability; respectively acquiring a starting IP address and an ending IP address corresponding to the IP address field, respectively converting the starting IP address and the ending IP address into a starting digital address and an ending digital address according to a preset conversion rule, and determining a digital address field set corresponding to the IP address field set; sequencing all the digital address fields in the digital address field set according to the sequence from small to large, and simultaneously sequentially storing the digital address fields corresponding to all the IP address fields and the corresponding geographic position information in an array to determine a positioning array;
a3, judging whether the target IP address meets the condition of locating the geographic position information of the digital address field corresponding to the median value according to the target digital address;
a4, if the condition is met, determining the geographic position positioning result of the target IP address according to the geographic position information of the digital address field corresponding to the median; or
And A5, if the condition is not met, determining a new positioning array according to the start value and the end value of the digital address field corresponding to the median, and returning to execute the step A2.
7. The electronic device of claim 6, wherein the step of determining a new location array according to the start value and the end value of the numeric address segment corresponding to the median value comprises:
and when the value of the target digital address is greater than or equal to the starting value of the digital address field corresponding to the median value and less than or equal to the ending value of the digital address field corresponding to the median value, judging that the target digital address meets the condition of locating the geographic position information of the digital address field corresponding to the median value, and the target IP address meets the condition of locating the geographic position information of the digital address field.
8. The electronic device according to claim 7, wherein the step of determining the sub-positioning array corresponding to the positioning array according to the start value and the end value of the IP address segment corresponding to the median value comprises:
when the target digital address is smaller than the initial value of the digital address segment corresponding to the median, taking a digital address segment set smaller than the initial value of the digital address segment corresponding to the median in the positioning array as a first new positioning array; or
And when the target digital address is larger than the end value of the digital address field corresponding to the median, taking the digital address field set larger than the end value of the digital address field corresponding to the median in the positioning array as a second new positioning array.
9. The electronic device according to claim 8, wherein the positioning program of the IP address, when executed by the processor, further implements the following steps:
generating prompt information according to the geographic position positioning result and displaying the prompt information; and
and when the digital address field containing the target digital address does not exist in the positioning array, generating first early warning information and prompting that the positioning fails.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium includes a program for locating an IP address, and when the program for locating an IP address is executed by a processor, the steps of the method for locating an IP address according to any one of claims 1 to 5 can be implemented.
CN201810547509.6A 2018-05-31 2018-05-31 Method and device for positioning IP address and storage medium Active CN108712519B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810547509.6A CN108712519B (en) 2018-05-31 2018-05-31 Method and device for positioning IP address and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810547509.6A CN108712519B (en) 2018-05-31 2018-05-31 Method and device for positioning IP address and storage medium

Publications (2)

Publication Number Publication Date
CN108712519A CN108712519A (en) 2018-10-26
CN108712519B true CN108712519B (en) 2022-07-08

Family

ID=63870113

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810547509.6A Active CN108712519B (en) 2018-05-31 2018-05-31 Method and device for positioning IP address and storage medium

Country Status (1)

Country Link
CN (1) CN108712519B (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109710860B (en) * 2018-12-21 2021-07-27 武汉思普崚技术有限公司 URL (Uniform resource locator) classification matching method and device
CN110266834B (en) * 2019-07-29 2022-08-26 中国工商银行股份有限公司 Area searching method and device based on internet protocol address
CN112532414B (en) * 2019-09-18 2023-05-02 中国移动通信集团河北有限公司 Method, device, equipment and computer storage medium for determining ISP attribution
CN111225079B (en) * 2019-12-31 2024-03-05 苏州三六零智能安全科技有限公司 Method, device, storage medium and device for positioning geographical position of malicious software author
CN111327721B (en) * 2020-02-28 2023-01-10 加和(北京)信息科技有限公司 IP address positioning method and device, storage medium and electronic device
CN112272157B (en) * 2020-09-15 2022-07-26 杭州数梦工场科技有限公司 Method and device for converting host IP address, computer equipment and storage medium
CN113191823B (en) * 2021-05-21 2023-01-20 聚好看科技股份有限公司 Method and server for targeted regional advertisement delivery
CN115022289B (en) * 2022-05-31 2023-08-15 苏州浪潮智能科技有限公司 Method, device, equipment and storage medium for detecting continuously available IP addresses
CN115277823A (en) * 2022-07-08 2022-11-01 北京达佳互联信息技术有限公司 Positioning method, positioning device, electronic equipment and storage medium
CN115190110B (en) * 2022-07-18 2024-01-09 北京抖音信息服务有限公司 Geographic position determining method and device

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103177000A (en) * 2011-12-21 2013-06-26 卓望数码技术(深圳)有限公司 Grouping method of Internet protocol (IP) addresses or cell phone numbers and query method of attribution place
CN104168341A (en) * 2014-08-15 2014-11-26 北京百度网讯科技有限公司 IP address locating method and CDN dispatching method and device
CN104333609A (en) * 2014-10-15 2015-02-04 北京百度网讯科技有限公司 IP address positioning method and device thereof
CN104539750A (en) * 2014-12-30 2015-04-22 深圳市兰丁科技有限公司 IP locating method and device
CN105512229A (en) * 2015-11-30 2016-04-20 北京奇艺世纪科技有限公司 IP address regional information storage, query method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103177000A (en) * 2011-12-21 2013-06-26 卓望数码技术(深圳)有限公司 Grouping method of Internet protocol (IP) addresses or cell phone numbers and query method of attribution place
CN104168341A (en) * 2014-08-15 2014-11-26 北京百度网讯科技有限公司 IP address locating method and CDN dispatching method and device
CN104333609A (en) * 2014-10-15 2015-02-04 北京百度网讯科技有限公司 IP address positioning method and device thereof
CN104539750A (en) * 2014-12-30 2015-04-22 深圳市兰丁科技有限公司 IP locating method and device
CN105512229A (en) * 2015-11-30 2016-04-20 北京奇艺世纪科技有限公司 IP address regional information storage, query method and device

Also Published As

Publication number Publication date
CN108712519A (en) 2018-10-26

Similar Documents

Publication Publication Date Title
CN108712519B (en) Method and device for positioning IP address and storage medium
CN108255958B (en) Data query method, device and storage medium
US9172666B2 (en) Locating a user based on aggregated tweet content associated with a location
US9940399B2 (en) Methods and systems for pathing analysis
CN106537384B (en) Use the reverse IP database of the data of instruction user location
US20150161207A1 (en) Assisting query and querying
CN108804516B (en) Similar user searching device, method and computer readable storage medium
CN111163072B (en) Method and device for determining characteristic value in machine learning model and electronic equipment
CN113412608B (en) Content pushing method and device, server and storage medium
WO2015043212A1 (en) Address information input method,acquisition method, apparatus,device and system
CN104539750A (en) IP locating method and device
WO2014007970A9 (en) Providing query suggestions
CN110427574B (en) Route similarity determination method, device, equipment and medium
CN110598131B (en) Method and device for determining user resident area, storage medium and electronic equipment
CN105610596B (en) Resource directory management method and network terminal
CN103399947A (en) Position based input method thesaurus management system and method
CN104156364A (en) Display method and device of map search result
CN104182446A (en) Method for searching data and method for planning itinerary
CN113918796A (en) Information searching method, device, server and storage medium
CN103646034A (en) Web search engine system and search method based content credibility
CN106844396B (en) Information processing method and electronic equipment
CN111274272B (en) Object searching method and device and computer system
CN110837606A (en) Spatio-temporal data fusion query method, device, server and storage medium
US20140330858A1 (en) Systems and methods for processing geographic data
CN112861532B (en) Address standardization processing method, device, equipment and online searching system

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