3

Now that all sun.* proprietary APIs may be removed in the future, does anyone know any open source Java implementation of IPv6 validation?

Regarding this question, it'd be also nice to have native ipv6-address/prefix-length format support to.

Community
  • 1
  • 1
wikier
  • 2,517
  • 2
  • 26
  • 39
  • Presumably, the APIs won't be removed until the Java platform provides equivalent functionality. Have you tried using `Inet6Address.getByAddress` or `InetAddress.getByName` as a validator? – Stephen C Sep 03 '12 at 09:39
  • Maybe [this lib from Jan Van Besien](http://janvanbesien.blogspot.co.uk/2011/10/java-library-for-ipv6.html) ? – Stewart Oct 31 '12 at 14:25
  • Caution: Inet6Address.getByName can lead to DNS queries if you feed e.g. a broken address like "::1::" into it. This can take a couple of seconds on a single call! – Dr. Hans-Peter Störr Mar 25 '13 at 17:55

2 Answers2

1

See the Guava library (there is isInetAddress() method)

stan
  • 984
  • 10
  • 15
1

The open-source IPAddress Java library will validate both IPv6 and IPv4 and also supports prefix-length (and validation of such). I am the project manager of that library.

Use

try {
    IPAddressString str = new IPAddressString("::1");
    IPAddress addr = str.toAddress();
} catch(IPAddressStringException e) {
    //e.getMessage has validation error
}
Michael Hampton
  • 9,737
  • 4
  • 55
  • 96
Sean F
  • 4,344
  • 16
  • 30