Package org.apache.commons.net.util
Class SubnetUtils
- java.lang.Object
-
- org.apache.commons.net.util.SubnetUtils
-
public class SubnetUtils extends java.lang.ObjectA class that 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 classSubnetUtils.SubnetInfoConvenience container for subnet summary information.
-
Field Summary
Fields Modifier and Type Field Description private intaddressprivate static java.util.regex.PatternaddressPatternprivate intbroadcastprivate static java.util.regex.PatterncidrPatternprivate booleaninclusiveHostCountWhether the broadcast/network address are included in host countprivate static java.lang.StringIP_ADDRESSprivate static intNBITSprivate intnetmaskprivate intnetworkprivate static java.lang.StringSLASH_FORMAT
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalculate(java.lang.String mask)private java.lang.Stringformat(int[] octets)SubnetUtils.SubnetInfogetInfo()Return aSubnetUtils.SubnetInfoinstance that contains subnet-specific statisticsbooleanisInclusiveHostCount()Returnstrueif the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network and broadcast addresses.private intmatchAddress(java.util.regex.Matcher matcher)(package private) intpop(int x)private intrangeCheck(int value, int begin, int end)voidsetInclusiveHostCount(boolean inclusiveHostCount)Set totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses.private int[]toArray(int val)private java.lang.StringtoCidrNotation(java.lang.String addr, java.lang.String mask)private inttoInteger(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
-
addressPattern
private static final java.util.regex.Pattern addressPattern
-
cidrPattern
private static final java.util.regex.Pattern cidrPattern
-
NBITS
private static final int NBITS
- See Also:
- Constant Field Values
-
netmask
private int netmask
-
address
private int address
-
network
private int network
-
broadcast
private 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)
Constructor that takes 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-3 decimal digits in range 1-32
-
SubnetUtils
public SubnetUtils(java.lang.String address, java.lang.String mask)Constructor that takes 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
-
isInclusiveHostCount
public boolean isInclusiveHostCount()
Returnstrueif the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network and broadcast addresses.- Returns:
- true if the hostcount includes the network and broadcast addresses
- Since:
- 2.2
-
setInclusiveHostCount
public void setInclusiveHostCount(boolean inclusiveHostCount)
Set totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses.- Parameters:
inclusiveHostCount- true if network and broadcast addresses are to be included- Since:
- 2.2
-
getInfo
public final SubnetUtils.SubnetInfo getInfo()
Return aSubnetUtils.SubnetInfoinstance that contains subnet-specific statistics- Returns:
- new instance
-
calculate
private void calculate(java.lang.String mask)
-
toInteger
private int toInteger(java.lang.String address)
-
matchAddress
private int matchAddress(java.util.regex.Matcher matcher)
-
toArray
private int[] toArray(int val)
-
format
private java.lang.String format(int[] octets)
-
rangeCheck
private int rangeCheck(int value, int begin, int end)
-
pop
int pop(int x)
-
toCidrNotation
private java.lang.String toCidrNotation(java.lang.String addr, java.lang.String mask)
-
-