提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
得到一个回圈NIF。
/** 来 自 时 代 Java - nowjava.com **/ //package com.nowjava; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getLoopbackNIF()); } /** * Get a loopback NIF. * @return a loopback NIF, <code>null</code> if not found. */ // TODO support case with multiple loopback NIFs public static NetworkInterface getLoopbackNIF() {/*来自 nowjava*/ Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException se) { return null; } while (nets.hasMoreElements()) { NetworkInterface net = nets.nextElement(); try { if (net.isUp() && net.isLoopback()) return net; } catch