OpenNMS API 1.2.3

org.opennms.netmgt.discovery
Class IPAddressRange

java.lang.Object
  extended byorg.opennms.netmgt.discovery.IPAddressRange

public final class IPAddressRange
extends java.lang.Object

The IPAddressRange object is used to encapsulate the starting and ending points of a continguous IPv4 Address range. The class can then generate either an Enumeration or Iterator that can be used to cycle through the range of addresses by the object's user.

Author:
Sowmya , Brian Weaver , OpenNMS

Nested Class Summary
(package private) static class IPAddressRange.IPAddressRangeGenerator
           This class is used to enumerate or iterate through one contiguous set of IP addresses.
 
Field Summary
private  long m_begin
          The starting address for the object.
private  long m_end
          The ending address for the object.
 
Constructor Summary
(package private) IPAddressRange(java.net.InetAddress start, java.net.InetAddress end)
           Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses.
(package private) IPAddressRange(java.lang.String fromIP, java.lang.String toIP)
           Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses.
 
Method Summary
(package private) static long byteToLong(byte b)
          Deprecated. Use org.opennms.netmgt.utils.IPSorter.byteToLong() instead.
(package private)  boolean contains(java.net.InetAddress ipAddr)
          This method may be used to determine if the specified IP address is contained within the IP address range.
(package private)  boolean contains(long ipAddr)
          This method may be used to determine if the specified IP address is contained within the IP address range.
(package private)  boolean contains(java.lang.String ipAddr)
          This method may be used to determine if the specified IP address is contained within the IP address range.
static long convertToLong(byte[] addr)
          Deprecated. Use org.opennms.netmgt.utils.IPSorter.convertToLong() instead.
(package private)  java.util.Enumeration elements()
           Returns an Enumeration object that can be used to list out all the address contained in the encapsulated range.
(package private)  long getBeginAddrAsLong()
          Returns the begin address of the IP address range as a long value.
(package private)  java.lang.String getBeginAddrAsString()
          Returns the begin address of the IP address range as a String value.
(package private)  long getEndAddrAsLong()
          Returns the end address of the IP address range as a long value.
(package private)  java.lang.String getEndAddrAsString()
          Returns the end address of the IP address range as a String value.
(package private) static java.lang.String IPv4String(int address)
           Converts a 32-bit unsigned quantity to a IPv4 dotted decimal string address.
(package private) static java.lang.String IPv4String(long address)
           Converts a 64-bit unsigned quantity to a IPv4 dotted decimal string address.
(package private)  java.util.Iterator iterator()
           Returns an Iterator object that can be used to step through all the address encapsulated in the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_begin

private long m_begin
The starting address for the object.


m_end

private long m_end
The ending address for the object.

Constructor Detail

IPAddressRange

IPAddressRange(java.lang.String fromIP,
               java.lang.String toIP)
         throws java.net.UnknownHostException

Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses. Once created the object can be used to get either an Iterator or Enumeration object to cycle through the list of address encapsulated by this object.

It is important to note that if the address for toIP is greater than fromIP, the values will be swapped so that the iteration is always from the lowest address to the highest address as defined by a 32-bit unsigned quantity.

Parameters:
fromIP - The starting address, resolved by InetAddress.
toIP - The ending address, resolved by InetAddress.
Throws:
java.net.UnknownHostException - Thrown by the InetAddress class if the hostname cannot be resolved.
See Also:
InetAddress.getByName(java.lang.String)

IPAddressRange

IPAddressRange(java.net.InetAddress start,
               java.net.InetAddress end)

Creates a new IPAddressRange object that can be used to encapsulate a contiguous range of IP Addresses. Once created the object can be used to get either an Iterator or Enumeration object to cycle through the list of address encapsulated by this object.

It is important to note that if the address for start is greater than end, the values will be swapped so that the iteration is always from the lowest address to the highest address as defined by a 32-bit unsigned quantity.

Parameters:
start - The starting address.
end - The ending address.
Method Detail

getBeginAddrAsString

java.lang.String getBeginAddrAsString()
Returns the begin address of the IP address range as a String value.

Returns:
Begin IP address as String.

getEndAddrAsString

java.lang.String getEndAddrAsString()
Returns the end address of the IP address range as a String value.

Returns:
End IP address as String.

getBeginAddrAsLong

long getBeginAddrAsLong()
Returns the begin address of the IP address range as a long value.

Returns:
Begin IP address as a long

getEndAddrAsLong

long getEndAddrAsLong()
Returns the end address of the IP address range as a long value.

Returns:
End IP address as a long

contains

boolean contains(long ipAddr)
This method may be used to determine if the specified IP address is contained within the IP address range.

Parameters:
ipAddr - IP address (long) to compare
Returns:
'true' if the specified IP address falls within the IP address range. 'false' otherwise.

contains

boolean contains(java.net.InetAddress ipAddr)
This method may be used to determine if the specified IP address is contained within the IP address range.

Parameters:
ipAddr - IP address (InetAddress) to compare
Returns:
'true' if the specified IP address falls within the IP address range. 'false' otherwise.

contains

boolean contains(java.lang.String ipAddr)
           throws java.net.UnknownHostException
This method may be used to determine if the specified IP address is contained within the IP address range.

Parameters:
ipAddr - IP address (String) to compare
Returns:
'true' if the specified IP address falls within the IP address range. 'false' otherwise.
Throws:
java.net.UnknownHostException

iterator

java.util.Iterator iterator()

Returns an Iterator object that can be used to step through all the address encapsulated in the object.

The iterator returns objects of type InetAddressor null if the address is unknown.

See Also:
InetAddress

elements

java.util.Enumeration elements()

Returns an Enumeration object that can be used to list out all the address contained in the encapsulated range.

The iterator returns objects of type InetAddressor null if the address is unknown.

See Also:
InetAddress

IPv4String

static java.lang.String IPv4String(long address)

Converts a 64-bit unsigned quantity to a IPv4 dotted decimal string address.

Parameters:
address - The 64-bit quantity to convert.
Returns:
The dotted decimal IPv4 address string.

IPv4String

static java.lang.String IPv4String(int address)

Converts a 32-bit unsigned quantity to a IPv4 dotted decimal string address.

Parameters:
address - The 32-bit quantity to convert.
Returns:
The dotted decimal IPv4 address string.

byteToLong

static long byteToLong(byte b)
Deprecated. Use org.opennms.netmgt.utils.IPSorter.byteToLong() instead.

Converts an 8-bit byte to a 64-bit long integer. If the quantity is a sign extended negative number then the value of 256 is added to wrap the conversion into the range of [0..255].

Parameters:
b - The byte to convert
Returns:
The converted 64-bit unsigned value.

convertToLong

public static long convertToLong(byte[] addr)
Deprecated. Use org.opennms.netmgt.utils.IPSorter.convertToLong() instead.

The convertToLong method takes an array of bytes and shifts them into a long value. The bytes at the front of the array are shifted into the MSB of the long as each new byte is added to the LSB of the long. if the array is of sufficent size the first bytes of the array may be shifted out of the returned long.

Parameters:
addr - The array to convert to a long.
Returns:
The created long value.
Throws:
java.lang.IllegalArgumentException - Thrown if the addr parameter is null.

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.