Class IPRange

java.lang.Object
  |
  +--IPRange
All Implemented Interfaces:
java.lang.Comparable

public class IPRange
extends java.lang.Object
implements java.lang.Comparable

IPRange constructors.


Field Summary
static int BYTES_PER_ADDRESS
          bytes needed to store an IP address range.
 
Constructor Summary
IPRange(java.net.InetAddress ipAddr, int bitsLong)
           
IPRange(java.lang.String unparsedString)
          constuct an IPRange if the bit length is not known.
IPRange(java.lang.String dottedDecimal, int bitsLong)
          creates new IP Address Range Object if the AS Number is not known.
IPRange(java.lang.String dottedDecimal, java.lang.String givenASN)
           
 
Method Summary
 void addChild(IPRange kid)
          add a subrange as a child to this IPRange.
 void checkMask()
          verify that the bitLen of the mask for an IP Address is plausible.
 int compareTo(java.lang.Object otherRange)
          compares this range to another.
 boolean covers(IPRange subrange)
          true if this range completely covers all addresses in the subrange.
 void delChild(int kidLocation)
          delete a subrange if its location is known in the children arraylist.
 void delChild(IPRange kid)
          delete a subrange as a child of this range (used when inserting a larger subrange).
static byte[] discoverAddr(java.lang.String str, int bitsLong)
          discover the 5-byte range for an IP address and mask length.
static java.lang.String discoverBaseIP(java.lang.String str)
          accepts a string representation of an IP Range and gives back the base address portion.
static int discoverBitLength(java.lang.String str)
          looks up the mask length for an IP Range.
 boolean dummy()
          true if this IPRange is a dummy range inserted to speed up searches.
 boolean equals(java.lang.Object otherRange)
           
static java.net.InetAddress findIPv4Address(java.lang.String dottedDecimal)
          convert ascii IP address (or name, actually) to an IP address.
 long fullRangeCount()
          the number of IP Addresses encompassed by this entire range, including any subranges.
 byte[] getAddress()
           
 java.lang.String getASN()
           
 int getASNum()
           
 int getBitLength()
           
 java.util.ArrayList getChildren()
           
 long getIPCount()
          the number of IP Addresses in this range, excluding any subranges.
 java.lang.String getPrintedName()
           
 boolean interior(long address)
          true if an IP Address is inside this range.
static IPRange loadAllRanges()
           
 long longAddr()
          returns the long representation of the base address.
static int lookupASNum(java.net.InetAddress address)
           
static int lookupASNum(IPAddress ipAddr)
           
static int lookupASNum(long address)
          translates an IPRange to its Autonomous System number.
static int lookupASNum(java.lang.String address)
           
 void setASN(int asNumber)
           
 void setASN(java.lang.String asn)
           
static long toLongAddr(byte[] b)
          converts a byte array representation of an IP address into a 64-bit long.
static long toLongAddr(java.lang.String str)
          converts an IP address string into a numerical address.
 java.lang.String toSortString()
           
static java.lang.String toSortString(byte[] addr, int bitLength)
           
static java.lang.String toSortString(java.lang.String unparsedString)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTES_PER_ADDRESS

public static final int BYTES_PER_ADDRESS
bytes needed to store an IP address range. For now just do 32 bit addresses (IPv4) plus the mask length.

See Also:
Constant Field Values
Constructor Detail

IPRange

public IPRange(java.lang.String dottedDecimal,
               int bitsLong)
creates new IP Address Range Object if the AS Number is not known.


IPRange

public IPRange(java.lang.String dottedDecimal,
               java.lang.String givenASN)

IPRange

public IPRange(java.lang.String unparsedString)
constuct an IPRange if the bit length is not known.


IPRange

public IPRange(java.net.InetAddress ipAddr,
               int bitsLong)
Method Detail

findIPv4Address

public static java.net.InetAddress findIPv4Address(java.lang.String dottedDecimal)
convert ascii IP address (or name, actually) to an IP address. Typical input would be "128.105.2.10".

Returns:
ipAddress the address in a form usable by sockets.

discoverBaseIP

public static java.lang.String discoverBaseIP(java.lang.String str)
accepts a string representation of an IP Range and gives back the base address portion. For example, 128.104.0.0/15 would return simply 128.104.0.0.

Returns:
basePortion the portion of the string containing the base IP address of the range.

discoverBitLength

public static int discoverBitLength(java.lang.String str)
looks up the mask length for an IP Range. This routine supplies mask lengths when they are implied by class A, B, or C address ranges.

Returns:
bitLen the length of the range mask in bits.

covers

public boolean covers(IPRange subrange)
true if this range completely covers all addresses in the subrange.


longAddr

public long longAddr()
returns the long representation of the base address. This representation makes comparisons easy.


toLongAddr

public static long toLongAddr(byte[] b)
converts a byte array representation of an IP address into a 64-bit long.


toLongAddr

public static long toLongAddr(java.lang.String str)
converts an IP address string into a numerical address.


discoverAddr

public static byte[] discoverAddr(java.lang.String str,
                                  int bitsLong)
discover the 5-byte range for an IP address and mask length. The input string is assumed to be an IPv4 address in dotted decimal notation.


checkMask

public void checkMask()
verify that the bitLen of the mask for an IP Address is plausible. If the low-order bits of the base address beyond the mask are not zero, the IP address is not the lowest IP address in the range. NOTE: this routine does not return an error. It prints an error message to stderr.


addChild

public void addChild(IPRange kid)
add a subrange as a child to this IPRange.


delChild

public void delChild(IPRange kid)
delete a subrange as a child of this range (used when inserting a larger subrange). For example, 128.0.0.0/8 might have a child, 128.104.0.0/16. Inserting 128.104.0.0/15 requires deleting the /16 from the /8 before making the /16 a child of the /15. Sorry for the mess.


delChild

public void delChild(int kidLocation)
delete a subrange if its location is known in the children arraylist.


getChildren

public java.util.ArrayList getChildren()

dummy

public boolean dummy()
true if this IPRange is a dummy range inserted to speed up searches.


getASNum

public int getASNum()

getAddress

public byte[] getAddress()

interior

public boolean interior(long address)
true if an IP Address is inside this range.


lookupASNum

public static int lookupASNum(long address)
translates an IPRange to its Autonomous System number.


lookupASNum

public static int lookupASNum(java.lang.String address)

lookupASNum

public static int lookupASNum(java.net.InetAddress address)

lookupASNum

public static int lookupASNum(IPAddress ipAddr)

loadAllRanges

public static IPRange loadAllRanges()

compareTo

public int compareTo(java.lang.Object otherRange)
compares this range to another. This routine is used for sorting lists of ranges.

Specified by:
compareTo in interface java.lang.Comparable

fullRangeCount

public long fullRangeCount()
the number of IP Addresses encompassed by this entire range, including any subranges.


getBitLength

public int getBitLength()

getPrintedName

public java.lang.String getPrintedName()

setASN

public void setASN(java.lang.String asn)

setASN

public void setASN(int asNumber)

getASN

public java.lang.String getASN()

getIPCount

public long getIPCount()
the number of IP Addresses in this range, excluding any subranges.


equals

public boolean equals(java.lang.Object otherRange)
Overrides:
equals in class java.lang.Object

toSortString

public static java.lang.String toSortString(java.lang.String unparsedString)

toSortString

public static java.lang.String toSortString(byte[] addr,
                                            int bitLength)

toSortString

public java.lang.String toSortString()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object