Class IpAddressMatcher


  • public class IpAddressMatcher
    extends Object
    Matches an InetAddress against a single IP address or a CIDR network range.

    Accepted forms:

    • Single address: 192.168.1.10, 2001:db8::1
    • CIDR range: 192.168.1.0/24, 2001:db8::/32
    Since:
    1.6.2
    Author:
    Ceki Gülcü
    • Constructor Detail

      • IpAddressMatcher

        public IpAddressMatcher​(String addressOrCidr)
        Creates a matcher for the given address or CIDR specification.
        Parameters:
        addressOrCidr - a single IP or address/prefixLength
        Throws:
        IllegalArgumentException - if the specification is invalid
    • Method Detail

      • matches

        public boolean matches​(InetAddress address)
        Returns true if the given address matches this matcher.
        Parameters:
        address - the address to test; may be null
        Returns:
        true if address matches
      • matches

        public boolean matches​(String address)
        Returns true if the given address string matches this matcher.
        Parameters:
        address - an IP address string
        Returns:
        true if the address matches
        Throws:
        IllegalArgumentException - if address cannot be parsed
      • getSpecification

        public String getSpecification()
        The original specification used to construct this matcher.