Final

java.net
Class NetworkInterface

java.lang.Object
  extended by java.net.NetworkInterface

public final class NetworkInterface
extends Object

This class provides an methods that are used to get information about the network interfaces supported by the system. A network interface can consist of multiple IP addresses assigned to a single interface name.


Method Summary
 boolean equals(Object obj)
          Compares the specified object to this NetworkInterface and answer if they are equal.
static NetworkInterface getByInetAddress(InetAddress address)
          Answers the network interface which has the specified inet address bound to it, if one exists.
static NetworkInterface getByName(String interfaceName)
          Answers the network interface with the specified name, if one exists
 String getDisplayName()
          Answers the user readable name associated with the network interface
 Enumeration getInetAddresses()
          Answers the list of inet addresses bound to the interface
 String getName()
          Answers the name associated with the network interface
static Enumeration getNetworkInterfaces()
          Answers the list of network interfaces supported by the system or null if no interfaces are supported by the system
 int hashCode()
          Answers a hash code for this NetworkInterface object.
 String toString()
          Answers a string containing a concise, human-readable description of the network interface
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getName

public String getName()
Answers the name associated with the network interface

Returns:
name associated with the network interface

getInetAddresses

public Enumeration getInetAddresses()
Answers the list of inet addresses bound to the interface

Returns:
list of inet addresses bound to the interface

getDisplayName

public String getDisplayName()
Answers the user readable name associated with the network interface

Returns:
display name associated with the network interface or null if one is not available

getByName

public static NetworkInterface getByName(String interfaceName)
                                  throws SocketException
Answers the network interface with the specified name, if one exists

Parameters:
interfaceName - name of interface to return
Returns:
network interface for name specified if it exists, otherwise null
Throws:
SocketException - if an error occurs when getting network interface information
NullPointerException - if the interface name passed in is null

getByInetAddress

public static NetworkInterface getByInetAddress(InetAddress address)
                                         throws SocketException
Answers the network interface which has the specified inet address bound to it, if one exists.

Parameters:
address - address of interest
Returns:
network interface for inet address specified if it exists, otherwise null
Throws:
SocketException - if an error occurs when getting network interface information
NullPointerException - if the address passed in is null

getNetworkInterfaces

public static Enumeration getNetworkInterfaces()
                                        throws SocketException
Answers the list of network interfaces supported by the system or null if no interfaces are supported by the system

Returns:
Enumeration containing one NetworkInterface object for each interface supported by the system
Throws:
SocketException - if an error occurs when getting network interface information

equals

public boolean equals(Object obj)
Compares the specified object to this NetworkInterface and answer if they are equal. The object must be an instance of NetworkInterface with the same name, displayName and list of network interfaces to be the same

Overrides:
equals in class Object
Parameters:
obj - the object to compare
Returns:
true if the specified object is equal to this NetworkInterfcae, false otherwise
See Also:
hashCode

hashCode

public int hashCode()
Answers a hash code for this NetworkInterface object. Since the name should be unique for each network interface the hash code is generated using this name

Overrides:
hashCode in class Object
Returns:
the hashcode for hashtable indexing
See Also:
Object.equals(java.lang.Object)

toString

public String toString()
Answers a string containing a concise, human-readable description of the network interface

Overrides:
toString in class Object
Returns:
a printable representation for the network interface

Final

Licensed Materials - Property of IBM
© Copyright IBM Corp. 2006, 2008 All Rights Reserved.