org.opengts.util
Class IPTools

java.lang.Object
  extended by org.opengts.util.IPTools

public class IPTools
extends java.lang.Object

A set of tools for handling IP Adresses


Nested Class Summary
static class IPTools.IPAddress
          IPAddress class
static class IPTools.IPAddressList
          Manages a list of IP address blocks
 
Field Summary
static java.lang.String HOST_UNKNOWN
           
static java.lang.String IP_ADDR_ALL
           
protected static long IP_ADDR_MASK
           
protected static int IP_ADDR_SIZE
           
static java.lang.String IPAddressSeparator
           
static char IPAddressSeparatorChar
           
static IPTools.IPAddressList PrivateIPAddresses
           
 
Constructor Summary
IPTools()
           
 
Method Summary
protected static long _parseIPAddress(java.lang.String ipAddr)
          Parses the specified IP address into it's binary form
protected static long _parseIPMask(int m)
          Parses an IP subnet mask [CHECK](better wording?)
static java.lang.String getHostName()
          Retruns name of the local host
static java.lang.String getIPAddress(java.lang.String hostName)
          Gets the IP adress of a specified host name though a DNS lookup
static boolean isLocalhost(java.lang.String hostName)
          Returns true if the specified hostname resolves to "localhost"
static boolean isPrivateIPAddress(java.lang.String ipAddr)
          Returns true if the specified IP address is private
static boolean isValidIPAddress(java.lang.String ipAddr)
          Returns true if the specified IP address is valid
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static long[] parseIPAddress(java.lang.String ipAddr)
          Parses the specified IPAddress/Mask and returns the result in a 2-element array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOST_UNKNOWN

public static final java.lang.String HOST_UNKNOWN
See Also:
Constant Field Values

IP_ADDR_ALL

public static final java.lang.String IP_ADDR_ALL
See Also:
Constant Field Values

IPAddressSeparatorChar

public static final char IPAddressSeparatorChar
See Also:
Constant Field Values

IPAddressSeparator

public static final java.lang.String IPAddressSeparator

IP_ADDR_SIZE

protected static final int IP_ADDR_SIZE
See Also:
Constant Field Values

IP_ADDR_MASK

protected static final long IP_ADDR_MASK
See Also:
Constant Field Values

PrivateIPAddresses

public static final IPTools.IPAddressList PrivateIPAddresses
Constructor Detail

IPTools

public IPTools()
Method Detail

getHostName

public static java.lang.String getHostName()
Retruns name of the local host

Returns:
The local host name

getIPAddress

public static java.lang.String getIPAddress(java.lang.String hostName)
Gets the IP adress of a specified host name though a DNS lookup

Parameters:
hostName - The specified host name
Returns:
the IP adress of the specified host, or an empty string

isLocalhost

public static boolean isLocalhost(java.lang.String hostName)
Returns true if the specified hostname resolves to "localhost"

Parameters:
hostName - The host name to check
Returns:
True if the specified hostname resolves to "localhost".

isValidIPAddress

public static boolean isValidIPAddress(java.lang.String ipAddr)
Returns true if the specified IP address is valid

Parameters:
ipAddr - The String representation of an IP address
Returns:
True if the specified IP address is valid, false otherwise.

isPrivateIPAddress

public static boolean isPrivateIPAddress(java.lang.String ipAddr)
Returns true if the specified IP address is private

Parameters:
ipAddr - The String representation of an IP address
Returns:
True if the specified IP address is private, false otherwise.

_parseIPAddress

protected static long _parseIPAddress(java.lang.String ipAddr)
Parses the specified IP address into it's binary form

Parameters:
ipAddr - The IP adress to parse as a string
Returns:
The parsed IP adress

_parseIPMask

protected static long _parseIPMask(int m)
Parses an IP subnet mask [CHECK](better wording?)

Parameters:
m - The length of the adress section
Returns:
The parsed IP subnet mask

parseIPAddress

public static long[] parseIPAddress(java.lang.String ipAddr)
Parses the specified IPAddress/Mask and returns the result in a 2-element array

Parameters:
ipAddr - The specified IPAddress/Mask
Returns:
A 2-element array containing the parsed IP address and mask

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments