1

I have a list of IP ranges specified with a CIDR. I want to compare the ranges and remove all the ranges which are already included in another one.

Example: I have:

10.152.0.0/14

10.152.2.0/24

10.153.3.0/24

In the Result only 10.152.0.0/14 should remain, because the other two are already included in that.

I tried with the org.apache.commons.net.util Package, but if im not wrong it can only compare a Range to an Adress and not compare Ranges itself.

Is there any library in Java that can help me compare those ranges?

Community
  • 1
  • 1
d4rky91
  • 23
  • 1
  • 7

1 Answers1

2

Please see the following link CIDRUtils. You'll need to do the checks yourself but the method call isInRange is implemented (it's not documented). This has also been answered before here

Community
  • 1
  • 1
anand1st
  • 1,086
  • 10
  • 16
  • 2
    Okay, this seems pretty much the same like the `isInRange` from org.apache.commons.net.util --> SubnetUtils.SubnetInfo. I was hoping there would be a way to compare two Ranges directly. – d4rky91 Jan 11 '17 at 15:41
  • Okay, I kind of did it like you suggested. I didn't use CIDRUtils, but as mentioned above the org.apache.commons.net.util package to create an object of each range in my list. After that I checked them manually by comparing the first and the last Ip from each range to all other ranges. I did that with the help of 'isInRange`and `getAllAddresses'. This would not work if ranges could overlap each other, which wasn't the case for me. – d4rky91 Jan 12 '17 at 13:00