com.atlassian.ip
Class IPMatcher

java.lang.Object
  extended by com.atlassian.ip.IPMatcher

public class IPMatcher
extends java.lang.Object

A Flexible, immutable, IP address matcher. Matches IP addresses against an internal database of IP addresses and IP subnets.

Performs DNS lookups only when adding hosts names using IPMatcher.Builder.addPatternOrHost(String). If using host names, instances of this class should be regularly discarded as any changes to DNS will not be picked up after the instance has been created.

Example usage:

final IPMatcher ipMatcher = IPMatcher.builder()
           .addPatternOrHost("example.org")
           .addPattern("192.168.1.0/24")
           .build();
   ipMatcher.match("192.168.1.13");


Nested Class Summary
static class IPMatcher.Builder
          A builder for creating immutable IPMatcher instances.
 
Method Summary
static IPMatcher.Builder builder()
          Returns a new builder.
static boolean isValidPatternOrHost(java.lang.String patternOrHost)
           
 boolean matches(java.net.InetAddress ipAddress)
          Returns true if the given ip address matches one of the stored patterns.
 boolean matches(java.lang.String ipAddress)
          Returns true if the given ip address matches one of the stored patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

matches

public boolean matches(java.lang.String ipAddress)
Returns true if the given ip address matches one of the stored patterns.

Parameters:
ipAddress - ip address to match
Returns:
true if the given ip address matches
Throws:
java.lang.IllegalArgumentException - if the argument is not a valid IP string literal

matches

public boolean matches(java.net.InetAddress ipAddress)
Returns true if the given ip address matches one of the stored patterns.

Parameters:
ipAddress - ip address to match
Returns:
true if the given ip address matches

isValidPatternOrHost

public static boolean isValidPatternOrHost(java.lang.String patternOrHost)

builder

public static IPMatcher.Builder builder()
Returns a new builder.

Returns:
new builder


Copyright © 2012 Atlassian. All Rights Reserved.