Java IP Address Get getPublicIps()

Here you can find the source of getPublicIps()

Description

get Public Ips

License

Open Source License

Declaration

public static Stream<InetAddress> getPublicIps() throws SocketException 

Method Source Code


//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());
    }
}

Related

  1. getPublicIP()
  2. getPublicIP()
  3. getPublicIP()
  4. getPublicIP2()
  5. getPublicIPAddress()
  6. getPublicIpViaHttp()
  7. getStrLocalIP()
  8. getVisibleIp()
  9. getWinLocalIP()