Java Utililty Methods Network Interface Get

List of utility methods to do Network Interface Get

Description

The list of methods to do Network Interface Get are organized into topic(s).

Method

CollectiongetNetworkInterfaces()
Utility method for accessing public interfaces.
final Collection<InetAddress> addresses = new ArrayList<InetAddress>();
final Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements()) {
    final NetworkInterface ni = e.nextElement();
    final Enumeration<InetAddress> niAddresses = ni.getInetAddresses();
    while (niAddresses.hasMoreElements()) {
        addresses.add(niAddresses.nextElement());
return addresses;
ListgetNetworkInterfaces()
get Network Interfaces
List<NetworkInterface> lst = new ArrayList<NetworkInterface>();
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements())
    lst.add(e.nextElement());
return lst;
CollectiongetNetworkInterfaces()
get Network Interfaces
Collection<String> itfs = getNetworkInterfaces(true);
return itfs;
ListgetNetworkInterfaces()
get Network Interfaces
List<NetworkInterface> networkInterfaces = new ArrayList<>();
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
    NetworkInterface networkInterface = interfaces.nextElement();
    networkInterfaces.add(networkInterface);
    Enumeration<NetworkInterface> subInterfaces = networkInterface.getSubInterfaces();
    if (subInterfaces.hasMoreElements()) {
        while (subInterfaces.hasMoreElements()) {
...
MethodgetNIOMulticastMethod()
get NIO Multicast Method
Method method = null;
try {
} catch (Throwable t) {
    method = null;
return method;
InetAddress[]getNonLoopbackLocalAdresses()
Returns list of machine assigned IP addresses excluding localhost/127.0.0.1
List<InetAddress> addrs = new ArrayList<InetAddress>();
for (InetAddress inetAddr : getLocalAddresses()) {
    if (!inetAddr.isLoopbackAddress()) {
        if (isPublic(inetAddr)) {
            addrs.add(0, inetAddr);
        } else {
            addrs.add(inetAddr);
return addrs.toArray(new InetAddress[addrs.size()]);
NetworkInterfacegetNonLoopbackNetworkInterface()
get Non Loopback Network Interface
Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
while (b.hasMoreElements()) {
    NetworkInterface networkInterface = b.nextElement();
    Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
    while (inetAddresses.hasMoreElements()) {
        InetAddress address = inetAddresses.nextElement();
        if (!address.isLoopbackAddress())
            return networkInterface;
...
NetworkInterfacegetPublicInterface()
get Public Interface
Enumeration<NetworkInterface> nets;
try {
    nets = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
    return null;
NetworkInterface netinf;
while (nets.hasMoreElements()) {
...
ListgetUsualNetworkInterfaces()
get Usual Network Interfaces
List<NetworkInterface> resultList = new ArrayList<NetworkInterface>();
Enumeration<NetworkInterface> allNetInterfaces;
try {
    allNetInterfaces = NetworkInterface.getNetworkInterfaces();
    while (allNetInterfaces.hasMoreElements()) {
        NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
        if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
            continue;
...
booleanisActive(String niName)
This method invoke the isUp for currently associated NetworkInterface
NetworkInterface ni = toNI(niName);
if (ni != null) {
    return ni.isUp();
return false;