Validate Ipv6/ipv4 address using InetAddress

3.2k Views Asked by At

In our project we need to use standard JAVA API 1.4.

We have been using InetAddress.getByNAme(String address) for validating Ipv6/v4 address. Now we are facing problem i.e if DNS configuration is not valid in our network then validation method takes more time to return result.

I have searched google for many alternatives to avoid DNS look up during validation and we have only one option getByAddress()

  1. Could any of you please suggest me how to convert IpAddress in String to byte array which is required as input parameter for getByAddress() method?
  2. Also can you please explain what does getByAddress() do to validate address? Does it look up for some local host?
1

There are 1 best solutions below

0
Paul Marks On BEST ANSWER

One possible approach is to use Guava's InetAddresses.forString() parser:

https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/net/InetAddresses.java