CN102469134A - IP (Internet Protocol) address search method and device - Google Patents
IP (Internet Protocol) address search method and device Download PDFInfo
- Publication number
- CN102469134A CN102469134A CN2010105476904A CN201010547690A CN102469134A CN 102469134 A CN102469134 A CN 102469134A CN 2010105476904 A CN2010105476904 A CN 2010105476904A CN 201010547690 A CN201010547690 A CN 201010547690A CN 102469134 A CN102469134 A CN 102469134A
- Authority
- CN
- China
- Prior art keywords
- address
- flag bit
- array
- data object
- ordering
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Abstract
The invention relates to the technical field of Internet and discloses an IP (Internet Protocol) address search method and device. The IP address search method and device provided by the invention have small occupied internal memory and simple size comparison by encoding IP into numbers; and furthermore, the IP address search method and device have the advantage of very high speed for ordering key values in a number group. By using a compromised comparison method for searching, the very high search efficiency can be achieved. A target in the IP database with more than one million records can be searched by only comparing for 20 times. According to the invention, compared with the method for searching the records one by one, the search efficiency is greatly improved.
Description
Technical field
The present invention relates to Internet technical field, in particular a kind of IP address retrieval methods and device.
Background technology
All kinds of Internet services are a lot of for the demand of providing personalized service according to the user area, this just require can be rapidly according to the address of User IP judges.The IP address detection method committed memory of prior art is big, calculation of complex, and inquiry velocity is unhappy, and efficient is not high yet.
Therefore, prior art awaits to improve and development.
Summary of the invention
The technical problem that the present invention will solve is, to the above-mentioned defective of prior art, a kind of IP address retrieval methods and device is provided, and it can find user's addresses according to User IP rapidly, and committed memory is little, treatment effeciency is high.
The technical scheme that technical solution problem of the present invention is adopted is following:
A kind of IP address retrieval methods wherein, comprises step:
A, set up the IP address base, and each bar record is set comprises: a start ip address, an end ip address and an actual address;
B, be IP From and End IP code conversion numeral;
C, put into an IP data object to the digital coding of End IP and address, and the IP data object is put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From, the ordering array is carried out index order to key assignments by numeral;
D, the IP that will search carry out digital coding, and three flag bits are set in ordering on the array and are respectively A, B, C: initial A flag bit is at the array head, and the C flag bit is at the array tail, and the B flag bit is in the middle of array;
E, relatively with the array key assignments at the IP digital coding of being inquired about and B flag bit place;
When greater than the time, then the A flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit, changes step f over to;
When less than the time, then the C flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit, changes step f over to;
When equaling, get into step g;
F, judge whether the AC flag bit is adjacent, the non-conterminous step e that then returns when A is adjacent with the C flag bit, judges that whether end ip address when being gets into step g more than or equal to inquiry IP address in the IP data object of A mark position;
G, the IP data object that key assignments identified of B flag bit is taken out, the actual address in the IP data object of this taking-up promptly is the address that this IP inquired about.
Described IP address retrieval methods, wherein, said step f also comprises: end ip address is then returned unknown IP address less than inquiry IP address in the IP of A mark position data object.
Described IP address retrieval methods, wherein, among the said step b is IP From and End IP code conversion that numeral comprises: is IP From and End IP code conversion integer.
A kind of IP address search device wherein, comprising:
The IP address base is set up module, is used to set up the IP address base, and each bar record is set comprises: a start ip address, an end ip address and an actual address;
Data-converting block be used for being numeral to IP From and End IP code conversion, and the IP that is used for searching carries out digital coding;
The ordering array is set up module; Be used for putting into an IP data object to the digital coding of End IP and address; And the IP data object put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From, the ordering array is carried out index order to key assignments by numeral;
Flag bit is provided with module, and be used on the ordering array, three flag bits being set and be respectively A, B, C: initial A flag bit is at the array head, and the C flag bit is at the array tail, and the B flag bit is in the middle of array;
Judge comparison module, be used for relatively the array key assignments at the IP digital coding of being inquired about and B flag bit place, when greater than the time, then the A flag bit is moved on to B and indicates bit position, the B flag bit resets to the centre of A and C flag bit; When less than the time, then the C flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit;
Adjacent judge module is used to judge whether the AC flag bit is adjacent;
The inquiry comparison module is used for when A is adjacent with the C flag bit, judges that whether end ip address is more than or equal to inquiry IP address in the IP data object of A mark position;
Actual address is taken out module, is used for the IP data object that key assignments identified of B flag bit is taken out, and the actual address in the IP data object of this taking-up promptly is the address that this IP inquired about.
Described IP address search device wherein, also comprises:
Unknown IP returns module, and the IP data object end ip address that is used for working as the A mark position is then returned unknown IP address less than inquiry IP address.
A kind of IP address retrieval methods provided by the present invention and device and since adopt IP is encoded to numeral after, committed memory is few; Big or small is simpler, and the speed that in array, key assignments is sorted is also very high, adopts the compromise comparison method during inquiry; Efficient is very high, and the IP database of 1,000,000 records just can find object as long as carry out 20 comparisons; Because it is very fast that computer carries out the speed of 20 comparisons, therefore improve very many than the efficient of searching one by one.
Description of drawings
Fig. 1 is the IP address retrieval methods flow chart that the embodiment of the invention provides.
Fig. 2 is the IP address base structure chart of the embodiment of the invention.
Fig. 3 is the IP data object structure chart of the embodiment of the invention.
Fig. 4 is the ordering structure of arrays figure of the embodiment of the invention.
Fig. 5 is the IP converting digital structure chart of one embodiment of the invention.
Fig. 6 is the refinement step flow chart that the IP according to the user of the embodiment of the invention adopts the compromise comparison method to retrieve fast.
Fig. 7 is the IP address search principle of device block diagram of the embodiment of the invention.
Embodiment
A kind of IP address retrieval methods provided by the present invention and device, clearer, clear and definite for making the object of the invention, technical scheme and advantage, below develop simultaneously embodiment to further explain of the present invention with reference to accompanying drawing.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
A kind of IP address retrieval methods that the embodiment of the invention provides, as shown in Figure 1, comprise step:
Step 110, set up the IP address base, and each bar record that is provided with in the IP address base comprises: a start ip address, an end ip address and an actual address, as shown in Figure 2; This type of IP address base can be searched on the internet to download and obtain.
Step 120, be IP From and End IP code conversion numeral; Wherein this numeral can be integer.Be IP From and End IP code conversion integer promptly.
For example; Coded system is following: like IP:202.4.79.6; Conversion regime is: 202*256*256*256+4*256*256+79*256+6-2147483648 (this numerical value is the minimum value of 32 integers in the computer), as shown in Figure 5, numeral is: 1241796358.
Step 130, put into an IP data object to the digital coding of End IP and address; As shown in Figure 3, and the IP data object put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From; As shown in Figure 4, the ordering array is carried out index order to key assignments by numeral;
Step 140, adopt the compromise comparison method to retrieve fast according to user's IP.
Wherein, as shown in Figure 6, this step 140 specifically comprises:
When A is adjacent with the C flag bit, get into step 146.
Be End IP coding in the result object more than or equal to this inquiry IP, then the address in this object is institute's inquire address, if less than, explain that then this IP not in this IP storehouse, is unknown IP.
Therefore after the present invention's employing was encoded to numeral with IP, committed memory was few; Big or small is simpler, and the speed that in array, key assignments is sorted is also very high, adopts the compromise comparison method during inquiry; Efficient is very high, and the IP database of 1,000,000 records just can find object as long as carry out 20 comparisons; The speed that computer carries out 20 comparisons is very fast, improves very many than the efficient of in 1,000,000 records, searching one by one.
Below will further specify the present invention through a concrete application implementation example: like certain section in the middle of the ordering array of an IP address base as follows: there are two numerals each position, and one is beginning IP, and one is End IP
… | 1200-1299 | 1300-1399 | 1400-1499 | 1500-1599 | 1600-1699 | … |
Such as the A sign is in this position of 1200-1299 now, and the C sign is in this position of 1600-1699, and the B sign is in this position of 1400-1499, and the IP that search is 1550 after converting numeral to.
Compare with 1400 of B flag bit with 1550,1550 greater than 1400, and the IP that explanation will be searched is between B and C.
Change to B mark position 1400-1499 to the A flag bit, the C flag bit is constant, or 1600-1699, and the B flag bit points to the 1500-1599 position in the middle of changing to A and C.
Compare with 1500 of B flag bit with 1550 once more, 1550 greater than 1500, and the IP that explanation will be searched is still between B and C; Once more the A flag bit is changed to B flag bit position, i.e. 1500-1599, the C flag bit is constant; Also at 1600-1699, the B flag bit is changed in the middle of A and the C, because of there not being other position in the middle of A and the C; So B gets middle preceding partially position, is still the 1500-1599 position.
This moment is because A is adjacent with C; The End IP numeral 1599,1550 of comparison 1550 and A flag bit is less than 1599, and the IP that explanation will be inquired about just drops in this IP segment limit of A flag bit sensing; According to the address of this IP segment limit representative in the database, just can obtain inquiring about the address of IP representative.
Based on a kind of IP address retrieval methods of the foregoing description, the embodiment of the invention also provides a kind of IP address search device, and is as shown in Figure 7, comprising:
The IP address base is set up module 710, is used to set up the IP address base, and each bar record is set comprises: a start ip address, an end ip address and an actual address;
Data-converting block 720 be used for being numeral to IP From and End IP code conversion, and the IP that is used for searching carries out digital coding.
The ordering array is set up module 730; Be used for putting into an IP data object to the digital coding of End IP and address; And the IP data object put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From, the ordering array is carried out index order to key assignments by numeral.
Flag bit is provided with module 740, and be used on the ordering array, three flag bits being set and be respectively A, B, C: initial A flag bit is at the array head, and the C flag bit is at the array tail, and the B flag bit is in the middle of array.
Judge comparison module 750, be used for relatively the array key assignments at the IP digital coding of being inquired about and B flag bit place, when greater than the time, then the A flag bit is moved on to B and indicates bit position, the B flag bit resets to the centre of A and C flag bit; When less than the time, then the C flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit;
Adjacent judge module 760 is used to judge whether the AC flag bit is adjacent.
Inquiry comparison module 770 is used for when A is adjacent with the C flag bit, judges that whether end ip address is more than or equal to inquiry IP address in the IP data object of A mark position.
Actual address is taken out module 780, is used for the IP data object that key assignments identified of B flag bit is taken out, and the actual address in the IP data object of this taking-up promptly is the address that this IP inquired about.
Further, described IP address search device, it also comprises:
Unknown IP returns module 790, and the IP data object end ip address that is used for working as the A mark position is then returned unknown IP address less than inquiry IP address.
In sum, a kind of IP address retrieval methods provided by the present invention and device since adopt IP is encoded to numeral after; Committed memory is few, and big or small is simpler, and the speed that in array, key assignments is sorted is also very high; Adopt the compromise comparison method during inquiry; Efficient is very high, and the IP database of 1,000,000 records just can find object as long as carry out 20 comparisons; The speed that computer carries out 20 comparisons is very fast, improves very many than the efficient of in 1,000,000 records, searching one by one.
Should be understood that application of the present invention is not limited to above-mentioned giving an example, concerning those of ordinary skills, can improve or conversion that all these improvement and conversion all should belong to the protection range of accompanying claims of the present invention according to above-mentioned explanation.
Claims (5)
1. an IP address retrieval methods is characterized in that, comprises step:
A, set up the IP address base, and each bar record is set comprises: a start ip address, an end ip address and an actual address;
B, be IP From and End IP code conversion numeral;
C, put into an IP data object to the digital coding of End IP and address, and the IP data object is put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From, the ordering array is carried out index order to key assignments by numeral;
D, the IP that will search carry out digital coding, and three flag bits are set in ordering on the array and are respectively A, B, C: initial A flag bit is at the array head, and the C flag bit is at the array tail, and the B flag bit is in the middle of array;
E, relatively with the array key assignments at the IP digital coding of being inquired about and B flag bit place;
When greater than the time, then the A flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit, changes step f over to;
When less than the time, then the C flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit, changes step f over to;
When equaling, get into step g;
F, judge whether the AC flag bit is adjacent, the non-conterminous step e that then returns when A is adjacent with the C flag bit, judges that whether end ip address when being gets into step g more than or equal to inquiry IP address in the IP data object of A flag bit;
G, the IP data object that key assignments identified of B flag bit is taken out, the actual address in the IP data object of this taking-up promptly is the address that this IP inquired about.
2. IP address retrieval methods according to claim 1 is characterized in that, said step f also comprises: end ip address is then returned unknown IP address less than inquiry IP address in the IP of A mark position data object.
3. IP address retrieval methods according to claim 1 is characterized in that, among the said step b is IP From and End IP code conversion that numeral comprises: is IP From and End IP code conversion integer.
4. an IP address search device is characterized in that, comprising:
The IP address base is set up module, is used to set up the IP address base, and each bar record is set comprises: a start ip address, an end ip address and an actual address;
Data-converting block be used for being numeral to IP From and End IP code conversion, and the IP that is used for searching carries out digital coding;
The ordering array is set up module; Be used for putting into an IP data object to the digital coding of End IP and address; And the IP data object put into the ordering array, and serve as the key assignments of ordering array with the digital coding of IP From, the ordering array is carried out index order to key assignments by numeral;
Flag bit is provided with module, and be used on the ordering array, three flag bits being set and be respectively A, B, C: initial A flag bit is at the array head, and the C flag bit is at the array tail, and the B flag bit is in the middle of array;
Judge comparison module, be used for relatively the array key assignments at the IP digital coding of being inquired about and B flag bit place, when greater than the time, then the A flag bit is moved on to B and indicates bit position, the B flag bit resets to the centre of A and C flag bit; When less than the time, then the C flag bit is moved on to B sign bit position, the B flag bit resets to the centre of A and C flag bit;
Adjacent judge module is used to judge whether the AC flag bit is adjacent;
The inquiry comparison module is used for when A is adjacent with the C flag bit, judges that whether end ip address is more than or equal to inquiry IP address in the IP data object of A mark position;
Actual address is taken out module, is used for the IP data object that key assignments identified of B flag bit is taken out, and the actual address in the IP data object of this taking-up promptly is the address that this IP inquired about.
5. IP address search device according to claim 4 is characterized in that, also comprises:
Unknown IP returns module, and the IP data object end ip address that is used for working as the A mark position is then returned unknown IP address less than inquiry IP address.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2010105476904A CN102469134A (en) | 2010-11-17 | 2010-11-17 | IP (Internet Protocol) address search method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2010105476904A CN102469134A (en) | 2010-11-17 | 2010-11-17 | IP (Internet Protocol) address search method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102469134A true CN102469134A (en) | 2012-05-23 |
Family
ID=46072297
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2010105476904A Pending CN102469134A (en) | 2010-11-17 | 2010-11-17 | IP (Internet Protocol) address search method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102469134A (en) |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103617205A (en) * | 2013-11-15 | 2014-03-05 | 北京奇虎科技有限公司 | Method and device for identifying regional attribution information of IP (internet protocol) addresses |
CN103855044A (en) * | 2014-03-31 | 2014-06-11 | 上海华力微电子有限公司 | Method for adding redundant graphics |
CN104539750A (en) * | 2014-12-30 | 2015-04-22 | 深圳市兰丁科技有限公司 | IP locating method and device |
CN104767839A (en) * | 2015-03-25 | 2015-07-08 | 五八有限公司 | IP positioning method and device |
CN106789137A (en) * | 2015-11-19 | 2017-05-31 | 北京国双科技有限公司 | The comparative approach and device of IP scopes |
CN106790748A (en) * | 2016-12-13 | 2017-05-31 | 小咖秀(北京)科技有限公司 | It is a kind of based on the C sections of immediate addressing dispatching method of IP |
CN106940708A (en) * | 2017-01-23 | 2017-07-11 | 北京思特奇信息技术股份有限公司 | A kind of method and system that the positioning of IP scopes is realized based on binary chop |
CN108777689A (en) * | 2018-06-08 | 2018-11-09 | 山东超越数控电子股份有限公司 | A kind of method of geographical location information corresponding to quick determining IP |
CN110134834A (en) * | 2019-05-15 | 2019-08-16 | 四川新网银行股份有限公司 | A method of accelerate IP to position using dynamic AVL forest cache |
CN112307138A (en) * | 2019-07-30 | 2021-02-02 | 华扬联众数字技术股份有限公司 | Storage and query method, system and medium of region information |
CN112398867A (en) * | 2020-11-23 | 2021-02-23 | 欧冶云商股份有限公司 | Black and white list limitation implementation method, platform, computer equipment and storage medium |
CN114201520A (en) * | 2021-12-09 | 2022-03-18 | 北京航星永志科技有限公司 | IP address quick retrieval method and device and electronic equipment |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1613066A (en) * | 2001-11-09 | 2005-05-04 | 瑞迪西斯迈克维尔通讯软件分公司 | Routing and forwarding table management for network processor architectures |
CN1904890A (en) * | 2006-08-15 | 2007-01-31 | 北京金山软件有限公司 | Method for searching IP dictionary and engine device for searching words |
-
2010
- 2010-11-17 CN CN2010105476904A patent/CN102469134A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1613066A (en) * | 2001-11-09 | 2005-05-04 | 瑞迪西斯迈克维尔通讯软件分公司 | Routing and forwarding table management for network processor architectures |
EP1657633B1 (en) * | 2001-11-09 | 2008-07-02 | RadiSys Corporation | Routing and forwarding table management for network processor architectures |
CN1904890A (en) * | 2006-08-15 | 2007-01-31 | 北京金山软件有限公司 | Method for searching IP dictionary and engine device for searching words |
Non-Patent Citations (1)
Title |
---|
王振兴,王智强,孙亚民,邬江兴: "基于二分搜索TriIPv4/IPv6路由快速查找算法", 《计算机工程》 * |
Cited By (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103617205A (en) * | 2013-11-15 | 2014-03-05 | 北京奇虎科技有限公司 | Method and device for identifying regional attribution information of IP (internet protocol) addresses |
WO2015070788A1 (en) * | 2013-11-15 | 2015-05-21 | 北京奇虎科技有限公司 | Method and device for identifying regional attribution information of ip address |
CN103855044A (en) * | 2014-03-31 | 2014-06-11 | 上海华力微电子有限公司 | Method for adding redundant graphics |
CN103855044B (en) * | 2014-03-31 | 2016-09-07 | 上海华力微电子有限公司 | A kind of method adding redundant pattern |
CN104539750A (en) * | 2014-12-30 | 2015-04-22 | 深圳市兰丁科技有限公司 | IP locating method and device |
CN104767839A (en) * | 2015-03-25 | 2015-07-08 | 五八有限公司 | IP positioning method and device |
CN106789137A (en) * | 2015-11-19 | 2017-05-31 | 北京国双科技有限公司 | The comparative approach and device of IP scopes |
CN106790748A (en) * | 2016-12-13 | 2017-05-31 | 小咖秀(北京)科技有限公司 | It is a kind of based on the C sections of immediate addressing dispatching method of IP |
CN106940708A (en) * | 2017-01-23 | 2017-07-11 | 北京思特奇信息技术股份有限公司 | A kind of method and system that the positioning of IP scopes is realized based on binary chop |
CN108777689A (en) * | 2018-06-08 | 2018-11-09 | 山东超越数控电子股份有限公司 | A kind of method of geographical location information corresponding to quick determining IP |
CN110134834A (en) * | 2019-05-15 | 2019-08-16 | 四川新网银行股份有限公司 | A method of accelerate IP to position using dynamic AVL forest cache |
CN110134834B (en) * | 2019-05-15 | 2023-06-09 | 四川新网银行股份有限公司 | Method for accelerating IP positioning by using dynamic AVL forest cache |
CN112307138A (en) * | 2019-07-30 | 2021-02-02 | 华扬联众数字技术股份有限公司 | Storage and query method, system and medium of region information |
CN112398867A (en) * | 2020-11-23 | 2021-02-23 | 欧冶云商股份有限公司 | Black and white list limitation implementation method, platform, computer equipment and storage medium |
CN114201520A (en) * | 2021-12-09 | 2022-03-18 | 北京航星永志科技有限公司 | IP address quick retrieval method and device and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102469134A (en) | IP (Internet Protocol) address search method and device | |
CN101404032B (en) | Video retrieval method and system based on contents | |
CN102377664A (en) | TCAM (ternary content addressable memory)-based range matching device and method | |
Yang et al. | A novel representation and compression for queries on trajectories in road networks | |
CN104539750A (en) | IP locating method and device | |
CN107330094B (en) | Bloom filter tree structure for dynamically storing key value pairs and key value pair storage method | |
CN102890719B (en) | A kind of method that license plate number is searched for generally and device | |
CN101751475B (en) | Method for compressing section records and device therefor | |
CN106570166B (en) | Video retrieval method and device based on multiple locality sensitive hash tables | |
CN113473127A (en) | Point cloud geometric coding method, point cloud geometric decoding method, point cloud geometric coding equipment and point cloud geometric decoding equipment | |
CN101848248B (en) | Rule searching method and device | |
CN1254921C (en) | Improved huffman decoding method and device | |
CN100476824C (en) | Method and system for storing element and method and system for searching element | |
CN101551820B (en) | Generation method and apparatus for index database of points of interest attribute | |
CN103354576A (en) | Mobile phone, and methods for storing and searching for mobile phone number attribution information | |
CN112307138A (en) | Storage and query method, system and medium of region information | |
CN1538329A (en) | Searching method of calalogue of stored items and its device | |
CN106407221B (en) | Address data retrieval method and device | |
CN105005464A (en) | Burrows Wheeler Transform hardware processing apparatus | |
CN103678385A (en) | Method for constructing personalized dictionary applicable to mobile search | |
CN103455491A (en) | Method and device for classifying search terms | |
CN105302833A (en) | Content based video retrieval mathematic model establishment method | |
CN115865099B (en) | Huffman coding-based multi-type data segment compression method and system | |
CN108345607A (en) | searching method and device | |
CN109213973B (en) | VIN code transcoding storage method and device and corresponding reading method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20120523 |