Here you can find the source of isInterfaceLoopback(NetworkInterface iface)
Parameter | Description |
---|---|
iface | the inteface that we'd like to determine as loopback or not. |
public static boolean isInterfaceLoopback(NetworkInterface iface)
//package com.java2s; /*/* w w w. j a v a 2 s .c o m*/ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * Maintained by the SIP Communicator community (http://sip-communicator.org). * * Distributable under LGPL license. * See terms of license at gnu.org. */ import java.lang.reflect.*; import java.net.*; import java.util.*; public class Main { /** * Determines whether or not the <tt>iface</tt> interface is a loopback * interface. We use this method as a replacement to the * <tt>NetworkInterface.isLoopback()</tt> method that only comes with * java 1.6. * * @param iface the inteface that we'd like to determine as loopback or not. * * @return true if <tt>iface</tt> contains at least one loopback address * and <tt>false</tt> otherwise. */ public static boolean isInterfaceLoopback(NetworkInterface iface) { try { Method method = iface.getClass().getMethod("isLoopback"); return ((Boolean) method.invoke(iface, new Object[] {})) .booleanValue(); } catch (Throwable t) { //apparently we are not running in a JVM that supports the //is Loopback method. we'll try another approach. } Enumeration<InetAddress> addresses = iface.getInetAddresses(); return addresses.hasMoreElements() && addresses.nextElement().isLoopbackAddress(); } }