I have 2 tables cidr
and ip
.
In the first one I store CIDR netmask's. (2 column table, id_cidr, cidr), here is an example (the values are fictional):
id_cidr | cidr
---------+----------------
1 | 14.44.182.0/24
---------+----------------
2 | 26.232.49.0/22
In the second one I want to store the ip's within each cidr netmask (3 column table, id_ip, cidr_id, ip), here is an example (the values are fictional):
id_ip | cidr_id | ip
---------+--------------------------
1 | 1 | 14.44.182.0
---------+--------------------------
2 | 1 | 14.44.182.1
---------+--------------------------
3 | 1 | 14.44.182.2
---------+--------------------------
... | 1 | ...
---------+--------------------------
256 | 1 | 14.44.182.255
---------+--------------------------
257 | 2 | 26.232.48.0
---------+--------------------------
258 | 2 | 26.232.48.1
---------+--------------------------
259 | 2 | 26.232.48.2
---------+--------------------------
... | 2 | ...
---------+--------------------------
1280 | 2 | 26.232.51.255
What I want to achieve is the following: whenever I addd a cidr netmask into the cidr table
I want my ip table
to auto-populate the fields with all the range of ip's within that cidr netmask. Is there any way to achieve this in mysql?
Note: To convert a cidr netmask to a range of ip's click here