5

I want to make an all-inclusive ip range in commons-net, but when I try

SubnetUtils subnetUtils = new SubnetUtils("0.0.0.0", "0.0.0.0");

or the same:

SubnetUtils subnetUtils = new SubnetUtils("0.0.0.0/0");

I get an exception:

java.lang.IllegalArgumentException: Value [0] not in range (0,32]
at org.apache.commons.net.util.SubnetUtils.rangeCheck(SubnetUtils.java:304)
at org.apache.commons.net.util.SubnetUtils.calculate(SubnetUtils.java:229)
at org.apache.commons.net.util.SubnetUtils.<init>(SubnetUtils.java:63)

I saw there is already a ticket for this: https://issues.apache.org/jira/browse/NET-511 . They say, that the issue is resolved in the next (3.4) release.

By the time commons-net 3.4 is released, is there any workaround (like a List of SubnetUtils objects) that together allows each IPv4 addresses?

kavai77
  • 6,282
  • 7
  • 33
  • 48

1 Answers1

2

Yes there is a workaround, with list of SubnetUtils objects, as you mentioned:

CIDR Signature: [0.255.255.255/1] Netmask: [128.0.0.0]
First Address:  [0.0.0.0]
Last Address:   [127.255.255.255]

CIDR Signature: [255.255.255.255/1] Netmask: [128.0.0.0]
First Address:  [128.0.0.0]
Last Address:   [255.255.255.255]

Or with Java code:

SubnetUtils subnetUtils1 = new SubnetUtils("0.255.255.255/1");
SubnetUtils subnetUtils2 = new SubnetUtils("255.255.255.255/1");
kavai77
  • 6,282
  • 7
  • 33
  • 48
btamas
  • 36
  • 2
  • 1
    Thanks. It's ridiculous that it is not allowed. How we are supposed to build a pass-all filter based on preferences? – NotGaeL Apr 08 '15 at 14:17