Ok, so lets assume I have 080080010000 (80.80.10.0) saved in the "low" field and 080080020255 (80.80.20.255) saved in the "high".
Someone attempts to add the range 80.80.12.0 - 80.80.25.255, the form process then converts this to 080080012000 - 080080025255 and ....does what?
set newLow = 080080012000
and newHigh = 080080025255
Then what you do is somehow extract all rows from the table in a sorted order (and here it might be good with some intelligent query statement if the table is very large).
Essentially loop through the sorted list until you find the last element which is less than newLow: in this example the row['low'] which is 080080010000 < 080080012000 which mean the newLow is inside an existing range.
Continue with newHigh as i described in the algorithm.
BUT,
What happens if someone wants to add a range that overlaps two existing ranges in the database?
Here it will end up with a merge and eventually removal of one record AND
For example 80.20.10.0 - 80.25.5.255 (some company's range) and 90.9.23.0 - 90.10.23.255 (game company's range) are in the database and someone tries to add 80.25.1.0 - 90.20.142.255 (just a made up range to mess with the database) it would merge the two ranges into one causing unrelated ips to be added to that range and also mess up the description's I have for each range (i.e. company's range, game company's range..etc).
Yes that will happen unless you don't put constraints on the entered ranges.
Since you want this to happen:
So what I want is for 80.80.10.0 - 80.80.20.255 to become 80.80.10.0 - 80.80.25.255 . I don't want two ranges with overlapping ips.
what are your constraints for not ending up with lets say,
80.80.10.0 - 80.80.95.255
or
80.80.10.0 - 80.200.25.255
or
80.80.10.0 - 255.255.255.255
This is the very tricky part in determining what is an allowed expansion which you have to decide and add to the algorithm.
Second question, how would you even get the leading zeros for the ip?
Is not hard since you know that all groups has three positions which means split up the entered ip range into four strings and if < 10 -> add two zeros
else if < 100 add one zero
for each group.
Second ex.
Say we have a range 80.80.10.0 - 80.80.20.255 in the database and someone tried to add a single ip to the list 80.80.15.213, how would I prevent that ip from being added since it's already within an existing range?
In this case is your newLow and newHigh the same and the algorithm will find that 'both' points are inside the same existing range and will not add it.
Third ex.
Say I have a single IP in the database 80.80.10.12 - 80.80.10.12
and someone adds the range 80.80.10.0 - 80.80.20.255 how would I update the single ip to use the new range?
The above algorithm will cover this as well.
Your biggest problem is to define the constraints for adding new ranges. Which means that
I'm not really sure how to prevent the merging of two existing ranges that are not meant to be merged but at the same time I'd like to allow it in a secure fashion.
will be very tricky.