Class InetAddressRange

java.lang.Object
org.apache.sshd.common.net.InetAddressRange

public final class InetAddressRange extends Object
Describes a range of IP addresses specified in CIDR notation.
  • Method Details

    • fromCIDR

      public static InetAddressRange fromCIDR(String cidr)
      Creates an InetAddressRange for a CIDR.
      Parameters:
      cidr - the CIDR
      Returns:
      an InetAddressRange
      Throws:
      IllegalArgumentException - if the cidr cannot be parsed as a CIDR.
    • isCIDR

      public static boolean isCIDR(String cidr)
      Tests whether a given string is a valid CIDR.
      Parameters:
      cidr - the string to test
      Returns:
      true if the string can be parsed as a CIDR; false otherwise
    • isIpV4

      public boolean isIpV4()
      Tells whether this is an IPv4 address range.
      Returns:
      true if this is an IPv4 address range, false otherwise
    • isIpV6

      public boolean isIpV6()
      Tells whether this is an IPv6 address range.
      Returns:
      true if this is an IPv6 address range, false otherwise
    • first

      public byte[] first(boolean inclusive)
      Retrieves the first address of this range as a MSB-first byte array.

      If subnetBits() <= 1, the address returned is always the zeroth address.

      Parameters:
      inclusive - whether to consider the zeroth address the first.
      Returns:
      the first address of the range
    • last

      public byte[] last(boolean inclusive)
      Retrieves the last address of this range as a MSB-first byte array.

      If subnetBits() <= 1, the address returned is always the broadcastAddress().

      Parameters:
      inclusive - whether to consider the direct broadcast address the last.
      Returns:
      the last address of the range
    • broadcastAddress

      public byte[] broadcastAddress()
      Retrieves the broadcast address of this range as a MSB-first byte array.
      Returns:
      the broadcast address of the range
    • contains

      public boolean contains(InetAddress address)
      Tests whether this range contains the given InetAddress.
      Parameters:
      address - InetAddress to test
      Returns:
      true if the address is in the range; false otherwise
    • contains

      public boolean contains(byte[] address)
      Tests whether this range contains the given IP address.
      Parameters:
      address - the IP address to test, as an MSB-first byte array
      Returns:
      true if the address is in the range; false otherwise
    • contains

      public boolean contains(InetAddressRange other)
      Tests whether this range completely contains a given other range.
      Parameters:
      other - InetAddressRange to test
      Returns:
      true if the other range is completely contained in this range; false otherwise
    • overlaps

      public boolean overlaps(InetAddressRange other)
      Tests whether this range overlaps a given other range.
      Parameters:
      other - InetAddressRange to test
      Returns:
      true if this range overlaps with the other range; false otherwise
    • networkZoneBits

      public int networkZoneBits()
      Retrieves the number of bits for the network zone.
      Returns:
      the number of bits for the network zone
    • subnetBits

      public int subnetBits()
      Retrieves the number of bits for the subnet.
      Returns:
      the number of bits for the subnet
    • numberOfAddresses

      public long numberOfAddresses(boolean inclusive)
      Determines the number of IP addresses in the range.

      If subnetBits() <= 1, the count always includes the first and last address.

      Parameters:
      inclusive - whether to include the first and last (broadcast) addresses in the count
      Returns:
      the number of addresses in the subnet
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object