Enum IpAddress

java.lang.Object
java.lang.Enum<IpAddress>
org.refcodes.net.IpAddress
All Implemented Interfaces:
Serializable, Comparable<IpAddress>, java.lang.constant.Constable

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

    • IPV4

      public static final IpAddress IPV4
      IPv4:
    • IPV6

      public static final IpAddress IPV6
      IPv6:
  • Method Details

    • values

      public static IpAddress[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static IpAddress valueOf(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:
      IllegalArgumentException - if this enum type has no constant with the specified name
      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 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 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 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 String toCidrNotation(int[] theIpAddress)
    • fromCidrNotation

      public int[] fromCidrNotation(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:
      IllegalArgumentException - Thrown in case the provided String is not of any known CIDR notation.
    • toString

      public static 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(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:
      IllegalArgumentException - Thrown in case the provided String is not of any known CIDR notation.
    • toHostIpAddress

      public static int[] toHostIpAddress() throws 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:
      IOException - Thrown to indicate that the IP address of a host could not be determined.
    • isAnyCidrNotation

      public static boolean isAnyCidrNotation(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(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 Set<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.