Enum IpAddress



  • public enum IpAddress
    extends java.lang.Enum<IpAddress>
    Metrics of an IP-Address as of IPv4 or IPv6.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      IPV4
      IPv4:
      IPV6
      IPv6:
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] fromAnyCidrNotation​(java.lang.String aCidrNotation)
      Creates an IP-Address as of an integer array for the first of the enumeration elements being able to successfully parse the provided String in CIDR notation.
      int[] fromCidrNotation​(java.lang.String aCidrNotation)
      Creates an IP-Address as of an integer array for the current enumeration from the provided String in CIDR notation.
      int[] getBroadcast​()
      The byte representation of the "broadcast" address (if the protocol supports a broadcast).
      char getCidrDelimiter​()
      The delimiter used by the CIDR notation.
      java.lang.String getCidrLocalhost​()
      Returns the CIDR notation of the localhost IP-Address.
      java.lang.String getCidrUnspecified​()
      Returns the CIDR notation of the unspecified IP-Address.
      int getLength​()
      Returns the length in bytes of the IP-Address.
      int[] getLocalhost​()
      The byte representation of the "localhost".
      java.lang.String getLocalhostAlias​()
      The commonly used alias for the "localhost".
      int[] getUnspecified​()
      The byte representation of the "unspecified".
      static boolean isAnyCidrNotation​(java.lang.String aCidrNotation)
      Determines whether the given String represents a valid IP-Address.
      static boolean isBroadcast​(int[] aIpAddress)
      Determines whether the given IP-Address is the broadcast address.
      boolean isCidrNotation​(java.lang.String aCidrNotation)
      Determines whether the given String represents a valid CIDR notation.
      static boolean isLocalhost​(int[] aIpAddress)
      Determines whether the given IP-Address represents the IP-Address of the "localhost" as of getLocalhost().
      static boolean isLoopback​(int[] aIpAddress)
      Determines whether the given IP-Address is in the scope of the the loopback interfaces.
      java.lang.String toCidrNotation​(int[] theIpAddress)  
      static int[] toHostIpAddress​()
      Tries to determine a no-localhost IP-Address for this machine.
      static java.lang.String toString​(int[] aIpAddress)
      Creates a String as of the CIDR notation from the provided IP-Address bytes.
      static java.util.Set<java.lang.String> toVisibleIpAddresses​()
      Tries to determine the known IP-Addresses from the accessible network segment.
      static IpAddress valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static IpAddress[] values​()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • IPV4

        public static final IpAddress IPV4
        IPv4:
      • IPV6

        public static final IpAddress IPV6
        IPv6:
    • Method Detail

      • values

        public static IpAddress[] values​()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (IpAddress c : IpAddress.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static IpAddress valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • getLength

        public int getLength​()
        Returns the length in bytes of the IP-Address.
        Returns:
        The IP-Address' length in bytes.
      • getUnspecified

        public int[] getUnspecified​()
        The byte representation of the "unspecified".
        Returns:
        The byte representation of the "unspecified".
      • getCidrUnspecified

        public java.lang.String getCidrUnspecified​()
        Returns the CIDR notation of the unspecified IP-Address. See also "https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation".
        Returns:
        The CIDR notation for "unspecified".
      • getLocalhost

        public int[] getLocalhost​()
        The byte representation of the "localhost".
        Returns:
        The byte representation of the "localhost".
      • getBroadcast

        public int[] getBroadcast​()
        The byte representation of the "broadcast" address (if the protocol supports a broadcast).
        Returns:
        The byte representation of the "broadcast" address or null if the protocol does not support a broadcast address.
      • getCidrLocalhost

        public java.lang.String getCidrLocalhost​()
        Returns the CIDR notation of the localhost IP-Address. See also "https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation".
        Returns:
        The CIDR notation for "localhost".
      • getLocalhostAlias

        public java.lang.String getLocalhostAlias​()
        The commonly used alias for the "localhost".
        Returns:
        The "localhost" alias.
      • getCidrDelimiter

        public char getCidrDelimiter​()
        The delimiter used by the CIDR notation. See also "https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation".
        Returns:
        The CIDR delimiter.
      • toCidrNotation

        public java.lang.String toCidrNotation​(int[] theIpAddress)
      • fromCidrNotation

        public int[] fromCidrNotation​(java.lang.String aCidrNotation)
        Creates an IP-Address as of an integer array for the current enumeration from the provided String in CIDR notation.
        Parameters:
        aCidrNotation - The String in CIDR notation to be parsed.
        Returns:
        The IP-Address as an array of integer values.
        Throws:
        java.lang.IllegalArgumentException - Thrown in case the provided String is not of any known CIDR notation.
      • toString

        public static java.lang.String toString​(int[] aIpAddress)
        Creates a String as of the CIDR notation from the provided IP-Address bytes. See also "https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation".
        Parameters:
        aIpAddress - The IP-Address for which to generate a String in CIDR notation.
        Returns:
        The String in CIDR notation.
      • isLocalhost

        public static boolean isLocalhost​(int[] aIpAddress)
        Determines whether the given IP-Address represents the IP-Address of the "localhost" as of getLocalhost().
        Parameters:
        aIpAddress - The IP-Address to be tested.
        Returns:
        True in case we have an IP-Address representing the localhost, else false.
      • isLoopback

        public static boolean isLoopback​(int[] aIpAddress)
        Determines whether the given IP-Address is in the scope of the the loopback interfaces.
        Parameters:
        aIpAddress - The IP-Address to be tested.
        Returns:
        True in case we have an IP-Address belonging to the loopback IP-Address block, else false.
      • isBroadcast

        public static boolean isBroadcast​(int[] aIpAddress)
        Determines whether the given IP-Address is the broadcast address.
        Parameters:
        aIpAddress - The IP-Address to be tested.
        Returns:
        True in case we have an IP-Address being the broadcast address, else false.
      • fromAnyCidrNotation

        public static int[] fromAnyCidrNotation​(java.lang.String aCidrNotation)
        Creates an IP-Address as of an integer array for the first of the enumeration elements being able to successfully parse the provided String in CIDR notation.
        Parameters:
        aCidrNotation - The String in CIDR notation to be parsed.
        Returns:
        The IP-Address as an array of integer values.
        Throws:
        java.lang.IllegalArgumentException - Thrown in case the provided String is not of any known CIDR notation.
      • toHostIpAddress

        public static int[] toHostIpAddress​()
                                     throws java.io.IOException
        Tries to determine a no-localhost IP-Address for this machine. The best guess is returned. If none no-localhost address is found, then the localhost's IP-Address may be returned (as of getLocalhost()).
        Returns:
        The best guest for a no-localhost IP-Address or as a fall back the localhost's IP-Address (as of getLocalhost()) may be returned.
        Throws:
        java.io.IOException - Thrown to indicate that the IP address of a host could not be determined.
      • isAnyCidrNotation

        public static boolean isAnyCidrNotation​(java.lang.String aCidrNotation)
        Determines whether the given String represents a valid IP-Address.
        Parameters:
        aCidrNotation - The Text in CIDR notation to be tested.
        Returns:
        True in case of being an IP-Address, else false.
      • isCidrNotation

        public boolean isCidrNotation​(java.lang.String aCidrNotation)
        Determines whether the given String represents a valid CIDR notation.
        Parameters:
        aCidrNotation - The Text in CIDR notation to be tested.
        Returns:
        True in case of being an IP-Address, else false.
      • toVisibleIpAddresses

        public static java.util.Set<java.lang.String> toVisibleIpAddresses​()
        Tries to determine the known IP-Addresses from the accessible network segment. It tries to invoke "arp -a" and also tries to manually detect the visible IP-Addresses.
        Returns:
        A set containing the visible IP-Addresses in CIDR notation.