public class IPRange extends Object
Modifier and Type | Field and Description |
---|---|
private int |
addressLength
Number of bits within the address.
|
private BitSet |
host
The IP host address, if a host address rather than a network address was specified.
|
private BitSet |
mask
The netmask for the range.
|
private BitSet |
network
The IP network address for the range.
|
Constructor and Description |
---|
IPRange(byte[] address,
int maskSize)
Constructor.
|
IPRange(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(InetAddress address)
Determines whether the given address is contained in the IP range.
|
InetAddress |
getHostAddress()
Returns the host address originally specified for this range, if it was a
host address rather than a network address.
|
InetAddress |
getNetworkAddress()
Returns the network address corresponding to this range as an
InetAddress . |
static IPRange |
parseCIDRBlock(String cidrBlock)
Parses a CIDR block definition in to an IP range.
|
protected BitSet |
toBitSet(byte[] bytes)
Converts a byte array to a BitSet.
|
private byte[] |
toByteArray(BitSet bits)
|
private InetAddress |
toInetAddress(BitSet bits)
Convert a
BitSet representing an address into an
equivalent InetAddress . |
private static void |
validateIPAddress(String address)
Validate an IP address for use as the base of a CIDR block.
|
private static void |
validateV4Address(String address)
Validate an IPv4 address for use as the base of a CIDR block.
|
private static void |
validateV6Address(String address)
Validate an IPv6 address for use as the base of a CIDR block.
|
private final int addressLength
private final BitSet network
private final BitSet host
private BitSet mask
public IPRange(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 InetAddress getNetworkAddress()
InetAddress
.InetAddress
public InetAddress getHostAddress()
InetAddress
, or nullprivate static void validateV4Address(String address)
address
- the address to validateprivate static void validateV6Address(String address)
InetAddress
parser.
Throws IllegalArgumentException if validation fails.address
- the address to validateprivate static void validateIPAddress(String address)
address
- the address to validatepublic static IPRange parseCIDRBlock(String cidrBlock)
cidrBlock
- the CIDR block definitionpublic boolean contains(InetAddress address)
address
- the address to checkpublic boolean contains(byte[] address)
address
- the address to checkprotected BitSet toBitSet(byte[] bytes)
bytes
- the byte array with most significant bit in element 0.private byte[] toByteArray(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 InetAddress toInetAddress(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 addressCopyright © 1999–2017. All rights reserved.