notation is more compact and easier to understand than writing out the mask in its traditional
dotted-decimal format.
130.5.5.25
10000010 . 00000101 . 00000101 . 00011001
255.255.255.0
11111111 . 11111111 . 11111111 . 00000000
<--extended-network-prefix -->
or
130.5.5.25/24
10000010 . 00000101 . 00000101 . 00011001
This class supports both standards : the extended network prefix and the subnet mask.
- Version:
- 1.0
- Author:
- Marcel Dullaart
- See Also:
IPAddress
IPRange
public IPRange(String range)
- Constructor.
- Parameters:
ip - String representation of the IP address. The two following formats are supported :
xxx.xxx.xxx.xxx/xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx/xx <- extended network prefix
- Throws:
InvalidIPRangeException - Throws this exception when the specified string doesn't represent a valid IP
address.
IPRange
public IPRange(IPAddress ipAddress,
IPAddress subnetMask)
- Constructor.
- Parameters:
ipAddress - Reference to the IP address numbersubnetMask - Reference to the subnet mask
- Throws:
InvalidIPRangeException - Throws this exception when the combination of the IP address and the subnet
mask does not define a valid IP range.
InvalidIPAddressException - Throws this exception if the specified IP address or subnet mask do ne
define a valid IP number.
IPRange
public IPRange(IPAddress ipAddress,
int extendedNetworkPrefix)
- Constructor.
- Parameters:
ipAddress - The reference on the IP address.extendedNetworkPrefix - The extended network prefix (0-32).
getIPAddress
public final IPAddress getIPAddress()
- Return the encapsulated IP address.
- Returns:
- The IP address.
getIPSubnetMask
public final IPAddress getIPSubnetMask()
- Return the encapsulated subnet mask
- Returns:
- The IP range's subnet mask.
getExtendedNetworkPrefix
public final int getExtendedNetworkPrefix()
- Return the extended extended network prefix.
- Returns:
- Return the extended network prefix.
toString
public String toString()
- Convert the IP Range into a string representation.
- Overrides:
toString in class Object
- Returns:
- Return the string representation of the IP Address following the common format xxx.xxx.xxx.xxx/xx (IP
address/extended network prefixs).
hashCode
public int hashCode()
- Overrides:
hashCode in class Object
equals
public boolean equals(Object another)
- Compare the specified IP range to the encapsulated one.
- Overrides:
equals in class Object
- Parameters:
another - The IP range to be compared.
- Returns:
- Return
true if the encapsulated IP range is the same as the specified one, otherwise return
false.
toDecimalString
public static String toDecimalString(String inBinaryIpAddress)
isIPAddressInRange
public boolean isIPAddressInRange(IPAddress address)
- Check if the specified IP address is in the encapsulated range.
- Parameters:
address - The IP address to be tested.
- Returns:
- Return
true if the specified IP address is in the encapsulated IP range, otherwise return
false.
Copyright © 2012 Alibaba Group. All Rights Reserved.