public class InetAddrValidation
extends java.lang.Object
InetAddrValidation is initialized with a particular IP range
specification. Calls to match method
will then quickly determine whether a given IP falls within that range.
Supported range specifications are:
12.34.56.782001:18e8:3:171:218:8bff:fe2a:56a412.34 (which matches any IP starting
12.34)18.25.0.0/255.255.0.018.25.0.0/16,
2001:18e8:3:171::/64| Constructor and Description |
|---|
InetAddrValidation() |
InetAddrValidation(java.lang.String ipSpec)
Construct an InetAddrValidation that will test for the given IP
specification
|
InetAddrValidation(java.lang.String lo,
java.lang.String hi) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkBlacklisted(java.lang.String ip,
java.util.Scanner blacklist)
Scan IP against a blacklist.
|
static boolean |
checkConnection(java.lang.String ip,
int port,
int timeout)
Check if given ip and port is available.
|
boolean |
checkIP(java.lang.String ip) |
boolean |
checkPermission(java.lang.String ip,
java.util.Scanner whitelist)
Scan IP against a whitelist (if given IP is allowed).
|
static java.util.Set<java.lang.String> |
getLocalAddresses() |
long |
ipToLong(java.net.InetAddress ip) |
boolean |
match(java.lang.String ipIn)
Determine whether the given full IP falls within the range this
InetAddrValidation was initialized with. |
public InetAddrValidation()
public InetAddrValidation(java.lang.String ipSpec)
throws GenericSEHRException
ipSpec - IP specification (full or partial address, network/netmask,
network/cidr)GenericSEHRException - if there is an error parsing the specification
(i.e. it is somehow malformed)public InetAddrValidation(java.lang.String lo,
java.lang.String hi)
throws java.net.UnknownHostException
java.net.UnknownHostExceptionpublic long ipToLong(java.net.InetAddress ip)
public boolean checkIP(java.lang.String ip)
throws java.net.UnknownHostException
java.net.UnknownHostExceptionpublic static java.util.Set<java.lang.String> getLocalAddresses()
throws GenericSEHRException
GenericSEHRExceptionpublic boolean checkPermission(java.lang.String ip,
java.util.Scanner whitelist)
whitelist can be a String, File, InputStream etc.
e.g. Scanner whitelist = new Scanner(new File "/etc/whitelist");
public boolean checkBlacklisted(java.lang.String ip,
java.util.Scanner blacklist)
whitelist can be a String, File, InputStream etc.
e.g. Scanner blacklist = new Scanner(new File "/etc/blacklist");
public boolean match(java.lang.String ipIn)
throws GenericSEHRException
InetAddrValidation was initialized with.ipIn - IP address as dot-delimited Stringtrue if the IP matches the range of this
InetAddrValidation; false otherwiseGenericSEHRException - if the IP passed in cannot be parsed correctly
(i.e. is malformed)public static boolean checkConnection(java.lang.String ip,
int port,
int timeout)
ip - port - timeout -