public class IPRange extends Object
Valid inputs are x.x.x.x/bits or z:z:z:z:z:z:z:z/bits. If /bits is missing, /32 vor IPv4 or /128 for IPv6 is assumed.
Modifier and Type | Class and Description |
---|---|
static class |
IPRange.RangeSet
Represents a set of IP ranges.
|
Modifier and Type | Field and Description |
---|---|
static IPRange |
IPV4_LOCALHOST
Represents the IP address of the localhost in an IPv4 environment
|
static IPRange |
IPV6_LOCALHOST
Represents the IP address of the localhost in an IPv6 environment
|
static IPRange.RangeSet |
LOCALHOST
Constant for a range which only accepts localhost.
|
static IPRange.RangeSet |
NO_FILTER
Constant for a "non filtering" range set which accepts all IP addresses
|
Constructor and Description |
---|
IPRange() |
Modifier and Type | Method and Description |
---|---|
boolean |
matches(InetAddress address)
Checks if the given IP is within the described ip range.
|
static IPRange.RangeSet |
paraseRangeSet(String commaSeparatedListOfRanges)
Compiles the given list of ranges into a range set.
|
static IPRange |
parseRange(String cidr)
Parses a CIDR expression and returns an IPRange
|
String |
toString() |
public static final IPRange.RangeSet NO_FILTER
public static final IPRange.RangeSet LOCALHOST
public static final IPRange IPV4_LOCALHOST
public static final IPRange IPV6_LOCALHOST
public static IPRange parseRange(String cidr)
cidr
- the CIDR expression to parse. This can be either an IP address like 192.168.1.4 or a subnet like
192.168.192.0/24 or empty which implies 0.0.0.0/0IllegalArgumentException
- in case of an invalid expressionpublic boolean matches(InetAddress address)
address
- the address to checkpublic static IPRange.RangeSet paraseRangeSet(String commaSeparatedListOfRanges)
commaSeparatedListOfRanges
- a string defining a list of ip ranges separated by a ",". Each ip range
can be an address or a sub net in CIDR notation.Copyright © 2018. All rights reserved.