java.net
Class InetAddress

java.lang.Object
  |
  +--java.net.InetAddress

public final class InetAddress
extends Object

A class that represents Internet addresses.


Method Summary
 boolean equals(Object obj)
          Compares this object against the specified object.
 byte[] getAddress()
          Returns the raw IP address in network byte order.
static InetAddress[] getAllByName(String host)
          Given a hostname, returns an array of all the corresponding InetAddresses.
static InetAddress getByName(String host)
          Returns a network address for the indicated host.
 String getHostAddress()
          Returns the IP address string "%d.%d.%d.%d"
 String getHostName()
          Gets the hostname for this address; also the key in the hashtable.
static InetAddress getLocalHost()
          Returns the local host.
 int hashCode()
          Returns a hashcode for this InetAddress.
 String toString()
          Converts the InetAddress to a String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getHostName

public String getHostName()
Gets the hostname for this address; also the key in the hashtable. If the host is equal to null, then this address refers to any of the local machine's available network addresses.


getAddress

public byte[] getAddress()
Returns the raw IP address in network byte order. The highest order byte position is in addr[0]. To be prepared for 64-bit IP addresses n array of bytes is returned.

Returns:
raw IP address in network byte order.

getHostAddress

public String getHostAddress()
Returns the IP address string "%d.%d.%d.%d"

Returns:
raw IP address in a string format

hashCode

public int hashCode()
Returns a hashcode for this InetAddress.

Overrides:
hashCode in class Object
See Also:
Hashtable

equals

public boolean equals(Object obj)
Compares this object against the specified object.

Overrides:
equals in class Object
Parameters:
obj - the object to compare against.
Returns:
true if the objects are the same; false otherwise.
See Also:
Hashtable

toString

public String toString()
Converts the InetAddress to a String.

Overrides:
toString in class Object

getByName

public static InetAddress getByName(String host)
                             throws UnknownHostException
Returns a network address for the indicated host. A host name of null refers to default address for the local machine. A local cache is used to speed access to addresses. If all addresses for a host are needed, use the getAllByName() method.

Parameters:
host - the specified host
Throws:
UnknownHostException - If the address is unknown.

getAllByName

public static InetAddress[] getAllByName(String host)
                                  throws UnknownHostException
Given a hostname, returns an array of all the corresponding InetAddresses.

Throws:
UnknownHostException - If the host name could not be resolved

getLocalHost

public static InetAddress getLocalHost()
                                throws UnknownHostException
Returns the local host.

Throws:
UnknownHostException - If the host name could not be resolved