public class IPRange
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private int |
addressLength
Number of bits within the address.
|
private java.util.BitSet |
host
The IP host address, if a host address rather than a network address was specified.
|
private java.util.BitSet |
mask
The netmask for the range.
|
private java.util.BitSet |
network
The IP network address for the range.
|
| Constructor and Description |
|---|
IPRange(byte[] address,
int maskSize)
Constructor.
|
IPRange(java.net.InetAddress address,
int maskSize)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(byte[] address)
Determines whether the given address is contained in the IP range.
|
boolean |
contains(java.net.InetAddress address)
Determines whether the given address is contained in the IP range.
|
java.net.InetAddress |
getHostAddress()
Returns the host address originally specified for this range, if it was a
host address rather than a network address.
|
java.net.InetAddress |
getNetworkAddress()
Returns the network address corresponding to this range as an
InetAddress. |
static IPRange |
parseCIDRBlock(java.lang.String cidrBlock)
Parses a CIDR block definition in to an IP range.
|
protected java.util.BitSet |
toBitSet(byte[] bytes)
Converts a byte array to a BitSet.
|
private byte[] |
toByteArray(java.util.BitSet bits)
Convert a
BitSet representing an address into an
equivalent array of bytes, sized according to the address
length of this IPRange. |
private java.net.InetAddress |
toInetAddress(java.util.BitSet bits)
Convert a
BitSet representing an address into an
equivalent InetAddress. |
private static void |
validateIPAddress(java.lang.String address)
Validate an IP address for use as the base of a CIDR block.
|
private static void |
validateV4Address(java.lang.String address)
Validate an IPv4 address for use as the base of a CIDR block.
|
private static void |
validateV6Address(java.lang.String address)
Validate an IPv6 address for use as the base of a CIDR block.
|
private final int addressLength
private final java.util.BitSet network
private final java.util.BitSet host
private java.util.BitSet mask
public IPRange(java.net.InetAddress address,
int maskSize)
address - address to base the range on; may be the network address or the
address of a host within the networkmaskSize - the number of bits in the netmaskpublic IPRange(byte[] address,
int maskSize)
address - address to base the range on; may be the network address or the
address of a host within the networkmaskSize - the number of bits in the netmaskpublic java.net.InetAddress getNetworkAddress()
InetAddress.InetAddresspublic java.net.InetAddress getHostAddress()
InetAddress, or nullprivate static void validateV4Address(java.lang.String address)
address - the address to validateprivate static void validateV6Address(java.lang.String address)
InetAddress parser.
Throws IllegalArgumentException if validation fails.address - the address to validateprivate static void validateIPAddress(java.lang.String address)
address - the address to validatepublic static IPRange parseCIDRBlock(java.lang.String cidrBlock)
cidrBlock - the CIDR block definitionpublic boolean contains(java.net.InetAddress address)
address - the address to checkpublic boolean contains(byte[] address)
address - the address to checkprotected java.util.BitSet toBitSet(byte[] bytes)
bytes - the byte array with most significant bit in element 0.private byte[] toByteArray(java.util.BitSet bits)
BitSet representing an address into an
equivalent array of bytes, sized according to the address
length of this IPRange.bits - BitSet representing an addressprivate java.net.InetAddress toInetAddress(java.util.BitSet bits)
BitSet representing an address into an
equivalent InetAddress.
Returns null for either a null BitSet or for any
problems encountered by InetAddress.bits - BitSet representing an addressInetAddress representing the same address