Class CIDRUtils


  • public class CIDRUtils
    extends Object
    A utility class that provides address evaluation (network and broadcast) and in-range functionality for a given IP Address from a CIDR specification. This utility supports both IPv4 and IPv6 addresses.



    IPv4 Example
    10.77.12.11/18 would produce 10.77.0.0 for the networkAddress and 10.77.63.255 for the broadcastAddress.

    IPv5 Example
    435:23f::45:23/101 would produce 435:23f:0:0:0:0:0:0 for the networkAddress and 435:23f:0:0:0:0:7ff:ffff for the broadcastAddress.

    Since:
    8.1
    • Method Detail

      • getNetworkAddress

        public String getNetworkAddress()
        Return the Network Address from the provided CIDR specification.
        Returns:
        the Network Address.
      • getBroadcastAddress

        public String getBroadcastAddress()
        Return the Broadcast Address from the provided CIDR specification.
        Returns:
        the Broadcast Address.
      • isInRange

        public boolean isInRange​(String ipAddress)
                          throws UnknownHostException
        Return whether an IP Address is within the provided CIDR specification.
        Returns:
        true if the IP Address is in range of the CIDR specification.
        Throws:
        UnknownHostException
      • toString

        public String toString()
        Return a string representation of the CIDR specification consisting of the start and end addresses.
        Overrides:
        toString in class Object
        Returns:
        the start and end addresses of the CIDR Specification.