NetworkInterface

public final class NetworkInterface extends Object

This class is used to represent a network interface of the local device. An interface is defined by its address and a platform dependent name. The class provides methods to get all information about the available interfaces of the system or to identify the local interface of a joined multicast group.

Public Method Summary

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.

Inherited Method Summary

Public Methods

public boolean equals (Object obj)

Compares the specified object to this 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.

Parameters
obj the object to compare with this instance.
Returns
  • true if the specified object is equal to this NetworkInterface, false otherwise.
See Also

public static NetworkInterface getByIndex (int index)

Returns the NetworkInterface corresponding to the given interface index, or null if no interface has this index.

Parameters
index
Throws
SocketException if an error occurs.

public static NetworkInterface getByInetAddress (InetAddress address)

Returns the NetworkInterface corresponding to the given address, or null if no interface has this address.

Parameters
address
Throws
SocketException if an error occurs.
NullPointerException if address == null.

public static