Hi Shekar,

Have you tried `java.net.preferIPv6Addresses` [1]? Setting
that property to `true` should result in IPv6 addresses, if
there are any,  being returned before IPv4 addresses.

-Chris.

[1] 
https://docs.oracle.com/javase/10/docs/api/java/net/doc-files/net-properties.html#Ipv4IPv6

> On 21 Aug 2018, at 18:21, S, Chandra Shekar (CDI R&D) 
> <chandra-sheka...@hpe.com> wrote:
> 
> Hello Experts,
>  
> This is regarding the Enhancement request  for a new method to give IPv6 
> address for the given host name.
> Currently we have a method InetAddress.getByName 
> <https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html#getByName(java.lang.String)>(String
>  <https://docs.oracle.com/javase/7/docs/api/java/lang/String.html> host) to 
> give the IPAddress for the given hostname.
>  
> If the DNS server resolves to both IPv4 and IPv6 addresses for the given 
> hostname, this method will return only the first IPv4 address.
> Actually this method queries the DNS server first for the IPv4 addresses (ie, 
> with option -query=A) and then queries the DNS server for the IPv6 (ie, with 
> option -query=AAAA) addresses.
> It consolidates the both IPv4 address and IPv6 address into the list, and 
> returns the first address from the consolidate list. As the IPv4 address will 
> be the first in the list , it always returns the IPv4 address only.
>  
> If we need to get only IPv6 address for the given host name (especially in 
> the IPv6Only environments), currently there is no such method/api for this.
> Currently we have method InetAddress.getAllByName 
> <https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html#getAllByName(java.lang.String)>(String
>  <https://docs.oracle.com/javase/7/docs/api/java/lang/String.html> host), 
> which gives both IPv4 address and IPv6 address  list, by iterating this we 
> can get the IPv6 address resolution.
> But it is nice to have a separate method to get/resolve to IPv6address. Ex : 
> getIPv6AddressByName(String 
> <https://docs.oracle.com/javase/7/docs/api/java/lang/String.html> host) or 
> getByName 
> <https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html#getByName(java.lang.String)>(String
>  <https://docs.oracle.com/javase/7/docs/api/java/lang/String.html> host, 
> AddressType addressType) – addressType will be passed by the call get 
> IPv4/IPv6 address.
> This new method can query the DNS only for the IPv6 address (ie, with option 
> -query=AAAA) which will have performance improvement over other.
>  
> Thanks & Regards
> Shekar

Reply via email to