public final class NetworkInterface extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
collectIpv6Addresses(String interfaceName,
int interfaceIndex,
List<InetAddress> addresses,
List<InterfaceAddress> interfaceAddresses)
Visible for testing only.
|
boolean |
equals(Object obj)
Compares the specified object to this
NetworkInterface and
returns whether they are equal or not. |
static NetworkInterface |
getByIndex(int index)
Returns the NetworkInterface corresponding to the given interface index, or null if no
interface has this index.
|
static NetworkInterface |
getByInetAddress(InetAddress address)
Returns the
NetworkInterface corresponding to the given address, or null if no
interface has this address. |
static NetworkInterface |
getByName(String interfaceName)
Returns the
NetworkInterface corresponding to the named network interface, or null
if no interface has this name. |
String |
getDisplayName()
Returns a human-readable name for this network interface.
|
byte[] |
getHardwareAddress()
Returns the hardware address of the interface, if it has one, or null otherwise.
|
int |
getIndex()
Returns the index for the network interface, or -1 if unknown.
|
Enumeration<InetAddress> |
getInetAddresses()
Returns an enumeration of the addresses bound to this network interface.
|
List<InterfaceAddress> |
getInterfaceAddresses()
Returns a List of the InterfaceAddresses for this network interface.
|
int |
getMTU()
Returns the Maximum Transmission Unit (MTU) of this interface.
|
String |
getName()
Returns the name of this network interface (such as "eth0" or "lo").
|
static Enumeration<NetworkInterface> |
getNetworkInterfaces()
Gets a list of all network interfaces available on the local system or
null if no interface is available. |
NetworkInterface |
getParent()
Returns the parent NetworkInterface of this interface if this is a
sub-interface, or null if it's a physical (non virtual) interface.
|
Enumeration<NetworkInterface> |
getSubInterfaces()
Returns an enumeration of all the sub-interfaces of this network interface.
|
int |
hashCode()
Returns the hash code for this
NetworkInterface. |
boolean |
isLoopback()
Returns true if this network interface is a loopback interface.
|
boolean |
isPointToPoint()
Returns true if this network interface is a point-to-point interface.
|
boolean |
isUp()
Returns true if this network interface is up.
|
boolean |
isVirtual()
Returns true if this interface is a virtual interface (also called
a sub-interface).
|
boolean |
supportsMulticast()
Returns true if this network interface supports multicast.
|
String |
toString()
Returns a string containing details of this network interface.
|
public int getIndex()
public String getName()
public Enumeration<InetAddress> getInetAddresses()
public String getDisplayName()
getName().public static NetworkInterface getByName(String interfaceName) throws SocketException
NetworkInterface corresponding to the named network interface, or null
if no interface has this name.SocketException - if an error occurs.NullPointerException - if interfaceName == null.public static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException
SocketExceptionpublic static NetworkInterface getByInetAddress(InetAddress address) throws SocketException
NetworkInterface corresponding to the given address, or null if no
interface has this address.SocketException - if an error occurs.NullPointerException - if address == null.public static NetworkInterface getByIndex(int index) throws SocketException
SocketException - if an error occurs.public static Enumeration<NetworkInterface> getNetworkInterfaces() throws SocketException
null if no interface is available.NetworkInterface instances representing the
available interfaces.SocketException - if an error occurs while getting the network interface
information.public boolean equals(Object obj)
NetworkInterface and
returns whether they are equal or not. The object must be an instance of
NetworkInterface with the same name, display name, and list
of interface addresses.equals in class Objectobj - the object to compare with this instance.true if the specified object is equal to this NetworkInterface, false otherwise.hashCode()public int hashCode()
NetworkInterface. Since the
name should be unique for each network interface the hash code is
generated using the name.hashCode in class ObjectObject.equals(java.lang.Object)public String toString()
public List<InterfaceAddress> getInterfaceAddresses()
public Enumeration<NetworkInterface> getSubInterfaces()
For example, eth0:1 would be a sub-interface of eth0.
public NetworkInterface getParent()
public boolean isUp()
throws SocketException
SocketException - if an I/O error occurs.public boolean isLoopback()
throws SocketException
SocketException - if an I/O error occurs.public boolean isPointToPoint()
throws SocketException
SocketException - if an I/O error occurs.public boolean supportsMulticast()
throws SocketException
SocketException - if an I/O error occurs.public byte[] getHardwareAddress()
throws SocketException
SocketException - if an I/O error occurs.public int getMTU()
throws SocketException
SocketException - if an I/O error occurs.public boolean isVirtual()