提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
按列表获取Inet地址
/** n o w j a v a . c o m **/ //package com.nowjava; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getInetAddressByList());/*时代Java公众号 提供*/ } public static List<InetAddress> getInetAddressByList() throws SocketException { List<InetAddress> list = new ArrayList<InetAddress>(); Enumeration<NetworkInterface> enumeration = NetworkInterface .getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> enumerationInetAddress = networkInterface