Check occurrences of IP addresses in a range with SQL or PL/SQL?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
Hi, my friends.


Tell amp-TA how with SQL (preferably) or PL/SQL implementations of the occurrence of specific IP addresses in a particular range?


Simply put, it is necessary to determine to which subnet belongs to a specific IP address:


There is a table ip_networks format

RANGE_BEGIN RANGE_END RANGE_NAME
10.160.1.0 10.160.1.125 MSK
10.160.1.126 10.160.1.254 SPB



... and many more...


and you want to display in the select query field value RANGE_NAME for each IP address from the long list.


My head is spinning something very long with the use of BETWEEN, FOR, and CASE, but I suspect that this problem is somehow more elementary must be addressed...


It is you hope...
by | 5 views

2 Answers

0 like 0 dislike
If the field type is inet, then:
\r
\rSELECT * FROM ips WHERE inet '10.160.1.15' >= RANGE_BEGIN AND inet '10.160.1.15' <= RANGE_END ;
by
0 like 0 dislike
Well as you can!
\r
Do ip unsigned int
record the lower of the ip range
the sample is first sorted list in ascending order, greater than or equal to the lower of the ip range
it is well and quickly, use the index
\r
If mysql cope with this, oracle should also work perfectly
\r
the only downside is you have unused blocks to write, but is an offline operation and is simple.
It is true for a particular region will be a lot of them. For the world wide everything will be just fine.
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
3 answers
0 like 0 dislike
4 answers
0 like 0 dislike
4 answers
asked Mar 21, 2019 by ayurganov
0 like 0 dislike
2 answers
asked Apr 21, 2019 by nicenice
110,608 questions
257,186 answers
0 comments
27,880 users