Java examples for Network:Network Address
get Inet Address By List
//package com.java2s; 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()); }/*from ww w . ja v a 2 s.c om*/ 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 .getInetAddresses(); while (enumerationInetAddress.hasMoreElements()) { list.add(enumerationInetAddress.nextElement()); } } return list; } }