Class InetAddresses

  • public class InetAddresses
    extends Object
    • Constructor Detail

      • InetAddresses

        public InetAddresses()
    • Method Detail

      • isInetAddress

        public static boolean isInetAddress​(String ipString)
      • toAddrString

        public static String toAddrString​(InetAddress ip)
        Returns the string representation of an InetAddress.

        For IPv4 addresses, this is identical to InetAddress.getHostAddress(), but for IPv6 addresses, the output follows RFC 5952 section 4. The main difference is that this method uses "::" for zero compression, while Java's version uses the uncompressed form.

        This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses such as "::c000:201". The output does not include a Scope ID.

        ip - InetAddress to be converted to an address string
        String containing the text-formatted IP address
      • forString

        public static InetAddress forString​(String ipString)
        Returns the InetAddress having the given string representation.

        This deliberately avoids all nameservice lookups (e.g. no DNS).

        ipString - String containing an IPv4 or IPv6 string literal, e.g. "" or "2001:db8::1"
        InetAddress representing the argument
        IllegalArgumentException - if the argument is not a valid IP string literal