Package org.apache.commons.net.util
Class SubnetUtils
- java.lang.Object
-
- org.apache.commons.net.util.SubnetUtils
-
public class SubnetUtils extends java.lang.Object
Performs some subnet calculations given a network address and a subnet mask.- Since:
- 2.0
- See Also:
- "http://www.faqs.org/rfcs/rfc1519.html"
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SubnetUtils.SubnetInfo
Convenience container for subnet summary information.
-
Field Summary
Fields Modifier and Type Field Description private int
address
private static java.util.regex.Pattern
ADDRESS_PATTERN
private int
broadcast
private static java.util.regex.Pattern
CIDR_PATTERN
private boolean
inclusiveHostCount
Whether the broadcast/network address are included in host countprivate static java.lang.String
IP_ADDRESS
private static int
NBITS
private int
netmask
private int
network
private static java.lang.String
PARSE_FAIL
private static java.lang.String
SLASH_FORMAT
-
Constructor Summary
Constructors Constructor Description SubnetUtils(java.lang.String cidrNotation)
Constructs an instance from a CIDR-notation string, e.g.SubnetUtils(java.lang.String address, java.lang.String mask)
Constructs an instance from a dotted decimal address and a dotted decimal mask.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SubnetUtils.SubnetInfo
getInfo()
Gets aSubnetUtils.SubnetInfo
instance that contains subnet-specific statisticsSubnetUtils
getNext()
SubnetUtils
getPrevious()
boolean
isInclusiveHostCount()
Tests if the return value ofSubnetUtils.SubnetInfo.getAddressCount()
includes the network and broadcast addresses.private static int
matchAddress(java.util.regex.Matcher matcher)
private static int
rangeCheck(int value, int begin, int end)
void
setInclusiveHostCount(boolean inclusiveHostCount)
Sets totrue
if you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()
to include the network and broadcast addresses.private static int
toInteger(java.lang.String address)
-
-
-
Field Detail
-
IP_ADDRESS
private static final java.lang.String IP_ADDRESS
- See Also:
- Constant Field Values
-
SLASH_FORMAT
private static final java.lang.String SLASH_FORMAT
- See Also:
- Constant Field Values
-
ADDRESS_PATTERN
private static final java.util.regex.Pattern ADDRESS_PATTERN
-
CIDR_PATTERN
private static final java.util.regex.Pattern CIDR_PATTERN
-
NBITS
private static final int NBITS
- See Also:
- Constant Field Values
-
PARSE_FAIL
private static final java.lang.String PARSE_FAIL
- See Also:
- Constant Field Values
-
netmask
private final int netmask
-
address
private final int address
-
network
private final int network
-
broadcast
private final int broadcast
-
inclusiveHostCount
private boolean inclusiveHostCount
Whether the broadcast/network address are included in host count
-
-
Constructor Detail
-
SubnetUtils
public SubnetUtils(java.lang.String cidrNotation)
Constructs an instance from a CIDR-notation string, e.g. "192.168.0.1/16"- Parameters:
cidrNotation
- A CIDR-notation string, e.g. "192.168.0.1/16"- Throws:
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-2 decimal digits in range 0-32
-
SubnetUtils
public SubnetUtils(java.lang.String address, java.lang.String mask)
Constructs an instance from a dotted decimal address and a dotted decimal mask.- Parameters:
address
- An IP address, e.g. "192.168.0.1"mask
- A dotted decimal netmask e.g. "255.255.0.0"- Throws:
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 zeros
-
-
Method Detail
-
matchAddress
private static int matchAddress(java.util.regex.Matcher matcher)
-
rangeCheck
private static int rangeCheck(int value, int begin, int end)
-
toInteger
private static int toInteger(java.lang.String address)
-
getInfo
public final SubnetUtils.SubnetInfo getInfo()
Gets aSubnetUtils.SubnetInfo
instance that contains subnet-specific statistics- Returns:
- new instance
-
getNext
public SubnetUtils getNext()
-
getPrevious
public SubnetUtils getPrevious()
-
isInclusiveHostCount
public boolean isInclusiveHostCount()
Tests if the return value ofSubnetUtils.SubnetInfo.getAddressCount()
includes the network and broadcast addresses.- Returns:
- true if the host count includes the network and broadcast addresses
- Since:
- 2.2
-
setInclusiveHostCount
public void setInclusiveHostCount(boolean inclusiveHostCount)
Sets totrue
if you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()
to include the network and broadcast addresses. This also applies toSubnetUtils.SubnetInfo.isInRange(int)
- Parameters:
inclusiveHostCount
- true if network and broadcast addresses are to be included- Since:
- 2.2
-
-