Here you can find the source of getPublicIps()
public static Stream<InetAddress> getPublicIps() 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.*; import java.util.stream.Stream; public class Main { public static Stream<InetAddress> getPublicIps() throws SocketException { return Collections.list(NetworkInterface.getNetworkInterfaces()).stream().filter(ni -> { try { return (!ni.isLoopback() && !ni.isPointToPoint()); } catch (SocketException e) { throw new RuntimeException("Failed to check network interface!", e); }/*w w w . ja va2 s . co m*/ }).flatMap(ni -> Collections.list(ni.getInetAddresses()).stream()).filter(ia -> !ia.isLinkLocalAddress()); } }