Java IP Address Get getInetIps()

Here you can find the source of getInetIps()

Description

get Inet Ips

License

Mozilla Public License

Declaration

public static List<String> getInetIps() 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*;

public class Main {

    public static List<String> getInetIps() {
        List<String> ipList = new LinkedList<>();
        try {/*from  w w w.  j  a  v a2  s. c o m*/
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            NetworkInterface networkInterface;
            Enumeration<InetAddress> inetAddresses;
            InetAddress inetAddress;
            String ip;
            while (networkInterfaces.hasMoreElements()) {
                networkInterface = networkInterfaces.nextElement();
                inetAddresses = networkInterface.getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    inetAddress = inetAddresses.nextElement();
                    if (inetAddress != null && inetAddress instanceof Inet4Address) {
                        ip = inetAddress.getHostAddress();
                        ipList.add(ip);
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return ipList;
    }
}

Related

  1. getHostIP()
  2. getHostIP()
  3. getHostIP()
  4. getHostIpAddress()
  5. getHostIPByHostName(String host)
  6. getIniFileInputStreamEclipse()
  7. getInputStreamFromZipFile( String zipFilePath, String resourcePath)
  8. getInterfaceAddress(final String ifaceName, final boolean ipV4)
  9. getInterfaceIPs()