You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michel Risucci (JIRA)" <ji...@apache.org> on 2015/10/27 21:32:27 UTC

[jira] [Comment Edited] (NET-405) Support for IPv6 in SubnetUtils

    [ https://issues.apache.org/jira/browse/NET-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14977103#comment-14977103 ] 

Michel Risucci edited comment on NET-405 at 10/27/15 8:32 PM:
--------------------------------------------------------------

Hi Gary.

The method "SubnetUtils#getInfo" creates a SubnetInfo instance with useful metadata, but "SubnetInfo#isInRange" is the most important.
I'm testing (exactly now, actually) Spring Security's "IpAddressMatcher", as [~mickael.tricot] said.
Since I am already familiar with Spring (my favorite Java framework), it was quite easy to use, and, according to my tests, it's working flawless!

For anyone wanting to check if some IPv4/IPv6 address is "in a subnet range", just try "org.springframework.security.web.util.matcher.IpAddressMatcher" like this:

{quote}
IpAddressMatcher v4Matcher = new IpAddressMatcher("192.168.0.1/24"); // IPv4 CIDR
IpAddressMatcher v6Matcher = new IpAddressMatcher("fe80:0:0:0:0:0:c0a8:1/120"); // IPv6 CIDR
v4Matcher.matches("192.168.0.11");
v6Matcher.matches("fe80:0:0:0:0:0:c0a8:11");
{quote}

According to documentation, "Both IPv6 and IPv4 addresses are supported, but a matcher which is configured with an IPv4 address will never match a request which returns an IPv6 address, and vice-versa." - In other words, just don't mix the matchers!


was (Author: michelrisucci):
Hi Gary.

The method "SubnetUtils#getInfo" creates a SubnetInfo instance with useful metadata, but "SubnetInfo#isInRange" is the most important.
I'm testing (exactly now, actually) Spring Security's "IpAddressMatcher", as [~mickael.tricot] said.
Since I am already familiar with Spring (my favorite Java framework), it was quite easy to use, and, according to my tests, it's working flawless!

For anyone wanting to check if some IPv4/IPv6 address is "in a subnet range", just try "org.springframework.security.web.util.matcher.IpAddressMatcher" like this:

IpAddressMatcher v4Matcher = new IpAddressMatcher("192.168.0.1/24"); // IPv4 CIDR
IpAddressMatcher v6Matcher = new IpAddressMatcher("fe80:0:0:0:0:0:c0a8:1/120"); // IPv6 CIDR
v4Matcher.matches("192.168.0.11");
v6Matcher.matches("fe80:0:0:0:0:0:c0a8:11");

According to documentation, "Both IPv6 and IPv4 addresses are supported, but a matcher which is configured with an IPv4 address will never match a request which returns an IPv6 address, and vice-versa." - In other words, just don't mix the matchers!

> Support for IPv6 in SubnetUtils
> -------------------------------
>
>                 Key: NET-405
>                 URL: https://issues.apache.org/jira/browse/NET-405
>             Project: Commons Net
>          Issue Type: Improvement
>            Reporter: Marc Lefrancois
>
> Currently, we cannot use org.apache.commons.net.util.SubnetUtils with IPv6 addresses. This class will become less and less useful as more internet device are only assigned IPv6 addresses since all available IPv4 address blocks have now been attributed. http://en.wikipedia.org/wiki/IPv4_address_exhaustion



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)