Here you can find the source of getLocalAddresses()
Parameter | Description |
---|---|
SocketException | if there was a problem talking to the network. |
public static Set<InetAddress> getLocalAddresses() throws SocketException
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; public class Main { /**/*w w w.j a va 2 s .c o m*/ * Get a set of local host addresses. * * @return Set of local host addresses. * @throws SocketException if there was a problem talking to the network. */ public static Set<InetAddress> getLocalAddresses() throws SocketException { Set<InetAddress> result = new HashSet<InetAddress>(); for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) { NetworkInterface ni = e.nextElement(); // complain(LOG_ALERT, getLogChannel(), "Interface: " + // ni.getDisplayName()); for (Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements();) { InetAddress niAddress = e2.nextElement(); // complain(LOG_ALERT, getLogChannel(), "Address: " + // niAddress); result.add(niAddress); } } return result; } }