Java IP Address Get getIPAdresses()

Here you can find the source of getIPAdresses()

Description

get IP Adresses

License

Open Source License

Declaration

public static InetAddress[] getIPAdresses() 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.ArrayList;

import java.util.Enumeration;
import java.util.List;

public class Main {
    public static InetAddress PUBLIC_IP;

    public static InetAddress[] getIPAdresses() throws SocketException {
        List<InetAddress> addrList = new ArrayList<InetAddress>();
        for (Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); nics
                .hasMoreElements();) {/*  w  ww. java 2  s.com*/
            NetworkInterface nic = nics.nextElement();
            if (nic.isUp()) {
                for (Enumeration<InetAddress> addresses = nic.getInetAddresses(); addresses.hasMoreElements();) {
                    InetAddress address = addresses.nextElement();
                    addrList.add(address);
                }
            }
        }
        addrList.add(PUBLIC_IP);
        return addrList.toArray(new InetAddress[0]);
    }
}

Related

  1. getIpAddressesFromNic()
  2. getIpAddressExternal()
  3. getIPAddressFromBytes(byte[] bytes)
  4. getIPAddressFromNetworkInterface(String ifaceName)
  5. getIPAddressFromNetworkInterfaces()
  6. getIpByHost(String hostName)
  7. getIpByHost(String hostName)
  8. getIpByHost(String hostName)
  9. getIPByInterfaceName(String name)