com.alibaba.druid.support.http.util
Class IPRange

java.lang.Object
  extended by com.alibaba.druid.support.http.util.IPRange

public class IPRange
extends Object

This class represents an IP Range, which are represented by an IP address and and a subnet mask. The standards describing modern routing protocols often refer to the extended-network-prefix-length rather than the subnet mask. The prefix length is equal to the number of contiguous one-bits in the traditional subnet mask. This means that specifying the network address 130.5.5.25 with a subnet mask of 255.255.255.0 can also be expressed as 130.5.5.25/24. The / 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

Constructor Summary
IPRange(IPAddress ipAddress, int extendedNetworkPrefix)
          Constructor.
IPRange(IPAddress ipAddress, IPAddress subnetMask)
          Constructor.
IPRange(String range)
          Constructor.
 
Method Summary
 boolean equals(Object another)
          Compare the specified IP range to the encapsulated one.
 int getExtendedNetworkPrefix()
          Return the extended extended network prefix.
 IPAddress getIPAddress()
          Return the encapsulated IP address.
 IPAddress getIPSubnetMask()
          Return the encapsulated subnet mask
 int hashCode()
           
 boolean isIPAddressInRange(IPAddress address)
          Check if the specified IP address is in the encapsulated range.
static String toDecimalString(String inBinaryIpAddress)
           
 String toString()
          Convert the IP Range into a string representation.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 number
    subnetMask - 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).
    Method Detail

    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.