Here you can find the source of getIPAddresses()
Parameter | Description |
---|---|
IOException | an exception |
public static List<InetAddress> getIPAddresses() throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /**//from ww w .j a v a2 s . c o m * List all IP addresses of the device, except loopback addresses. * * @return a List of IP addresses * @throws IOException */ public static List<InetAddress> getIPAddresses() throws IOException { List<InetAddress> addresses = new ArrayList<InetAddress>(); List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress a : addrs) { if (a.isLoopbackAddress()) { continue; } addresses.add(a); } } return addresses; } }