0

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?
sailaja kasanur
  • 87
  • 1
  • 2
  • 11
  • I can't speak for Java 1.4 (because it's been out of support for *seven years* and the documentation isn't readily available anymore), but the documentation from Java 1.7 says this about `getByName(String)` " If a literal IP address is supplied, only the validity of the address format is checked." – Ian McLaird Mar 24 '15 at 16:52
  • Likely, your answer is here http://stackoverflow.com/questions/9129391/inet-ntoa-and-inet-aton-in-java Hint: you need the equivalent of BSD inet_aton() and friends. –  Mar 24 '15 at 17:49
  • 1
    Your question is meaningless. If you already know the IP address you don't need to validate anything. If your DNS is slow or invalid, fix it. That's the only thing that can 'validate' hostnames."Avoid DNS look up during validation" is a contradiction in terms. – user207421 Mar 25 '15 at 00:44
  • @IanMcLaird yes Java 1.4 is outdated but our project is not yet moved to latest so my hands are tied. thanks for the suggestion. – sailaja kasanur Mar 25 '15 at 04:24

1 Answers1

0

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

Paul Marks
  • 126
  • 5