public class SubnetUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
SubnetUtils.SubnetInfo
Convenience container for subnet summary information.
|
Modifier and Type | Field and Description |
---|---|
private int |
address |
private static java.util.regex.Pattern |
addressPattern |
private int |
broadcast |
private static java.util.regex.Pattern |
cidrPattern |
private boolean |
inclusiveHostCount
Whether the broadcast/network address are included in host count
|
private static java.lang.String |
IP_ADDRESS |
private static int |
NBITS |
private int |
netmask |
private int |
network |
private static java.lang.String |
SLASH_FORMAT |
Constructor and Description |
---|
SubnetUtils(java.lang.String cidrNotation)
Constructor that takes a CIDR-notation string, e.g.
|
SubnetUtils(java.lang.String address,
java.lang.String mask)
Constructor that takes a dotted decimal address and a dotted decimal mask.
|
Modifier and Type | Method and Description |
---|---|
private void |
calculate(java.lang.String mask) |
private java.lang.String |
format(int[] octets) |
SubnetUtils.SubnetInfo |
getInfo()
Return a
SubnetUtils.SubnetInfo instance that contains subnet-specific statistics |
boolean |
isInclusiveHostCount()
Returns
true if the return value of SubnetUtils.SubnetInfo.getAddressCount()
includes the network and broadcast addresses. |
private int |
matchAddress(java.util.regex.Matcher matcher) |
(package private) int |
pop(int x) |
private int |
rangeCheck(int value,
int begin,
int end) |
void |
setInclusiveHostCount(boolean inclusiveHostCount)
Set to
true if you want the return value of SubnetUtils.SubnetInfo.getAddressCount()
to include the network and broadcast addresses. |
private int[] |
toArray(int val) |
private java.lang.String |
toCidrNotation(java.lang.String addr,
java.lang.String mask) |
private int |
toInteger(java.lang.String address) |
private static final java.lang.String IP_ADDRESS
private static final java.lang.String SLASH_FORMAT
private static final java.util.regex.Pattern addressPattern
private static final java.util.regex.Pattern cidrPattern
private static final int NBITS
private int netmask
private int address
private int network
private int broadcast
private boolean inclusiveHostCount
public SubnetUtils(java.lang.String cidrNotation)
cidrNotation
- A CIDR-notation string, e.g. "192.168.0.1/16"java.lang.IllegalArgumentException
- if the parameter is invalid,
i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-3 decimal digits in range 1-32public SubnetUtils(java.lang.String address, java.lang.String mask)
address
- An IP address, e.g. "192.168.0.1"mask
- A dotted decimal netmask e.g. "255.255.0.0"java.lang.IllegalArgumentException
- if the address or mask is invalid,
i.e. does not match n.n.n.n where n=1-3 decimal digits and the mask is not all zerospublic boolean isInclusiveHostCount()
true
if the return value of SubnetUtils.SubnetInfo.getAddressCount()
includes the network and broadcast addresses.public void setInclusiveHostCount(boolean inclusiveHostCount)
true
if you want the return value of SubnetUtils.SubnetInfo.getAddressCount()
to include the network and broadcast addresses.inclusiveHostCount
- true if network and broadcast addresses are to be includedpublic final SubnetUtils.SubnetInfo getInfo()
SubnetUtils.SubnetInfo
instance that contains subnet-specific statisticsprivate void calculate(java.lang.String mask)
private int toInteger(java.lang.String address)
private int matchAddress(java.util.regex.Matcher matcher)
private int[] toArray(int val)
private java.lang.String format(int[] octets)
private int rangeCheck(int value, int begin, int end)
int pop(int x)
private java.lang.String toCidrNotation(java.lang.String addr, java.lang.String mask)