Here you can find the source of isInterfaceUp(NetworkInterface iface)
Parameter | Description |
---|---|
iface | the interface that we'd like to determine as Up or Down. |
public static boolean isInterfaceUp(NetworkInterface iface)
//package com.java2s; /*//from w w w .j a v a2s .co 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.*; public class Main { /** * Determines, if possible, whether or not the <tt>iface</tt> interface is * up. We use this method so that we could use {@link * java.net.NetworkInterface}'s <tt>isUp()</tt> when running a JVM that * supports it and return a default value otherwise. * * @param iface the interface that we'd like to determine as Up or Down. * * @return <tt>false</tt> if <tt>iface</tt> is known to be down and * <tt>true</tt> if the <tt>iface</tt> is Up or in case we couldn't * determine. */ public static boolean isInterfaceUp(NetworkInterface iface) { try { Method method = iface.getClass().getMethod("isUp"); return ((Boolean) method.invoke(iface)).booleanValue(); } catch (Throwable t) { //apparently we are not running in a JVM that supports the //isUp method. returning default value. } return true; } }