Class IpSubnet

java.lang.Object
org.graylog2.utilities.IpSubnet

public class IpSubnet extends Object
A class that enables to get an IP range from CIDR specification. It supports both IPv4 and IPv6.
  • Constructor Details

  • Method Details

    • getNetworkAddress

      public String getNetworkAddress()
    • getBroadcastAddress

      public String getBroadcastAddress()
    • contains

      public boolean contains(String ipAddress) throws UnknownHostException
      Throws:
      UnknownHostException
    • contains

      public boolean contains(InetAddress address)
    • getPrefixLength

      public int getPrefixLength()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • formatCIDR

      public static Optional<String> formatCIDR(String value)
      Formats the given value in CIDR notation. If the value is already valid CIDR just return it. Otherwise, check if the value is an individual IP address. If it is, add the appropriate /32 or /128 depending on if the IP is v4 or v6. If the value is not already valid CIDR notation or an IP address, return empty.
      Parameters:
      value - string value to be formatted as CIDR
      Returns:
      optional valid CIDR formatted String