Check if network is loopback in Java

Description

The following code shows how to check if network is loopback.

Example


import java.net.NetworkInterface;
import java.util.Enumeration;
//from  w  w w .  j  a v  a2  s . co  m
public class Main {
  public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = en.nextElement();
      System.out.println(" Display Name = " + ni.getDisplayName());
      System.out.println(" Is loopback = " + ni.isLoopback());
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode