Class IpAddressMatcher

java.lang.Object
ch.qos.logback.core.util.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 Details

    • 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 Details

    • 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

      The original specification used to construct this matcher.
    • toString

      public String toString()
      Overrides:
      toString in class Object