Java IP Address Get getALLLocalHostIP()

Here you can find the source of getALLLocalHostIP()

Description

get ALL Local Host IP

License

Open Source License

Declaration

public static String[] getALLLocalHostIP() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {

    public static String[] getALLLocalHostIP() {
        String[] ipSet = null;//from  w  w  w.  j  ava 2  s. com
        String hostName = getLocalHostName();
        if (hostName.length() > 0) {
            try {
                InetAddress[] addresses = InetAddress.getAllByName(hostName);
                ipSet = new String[addresses.length];

                for (int i = 0; i < addresses.length; i++) {
                    ipSet[i] = addresses[i].getHostAddress();
                }
            } catch (UnknownHostException e) {
                ipSet = null;
            }
        }

        return ipSet;
    }

    public static String getLocalHostName() {
        String name = "";
        try {
            InetAddress address = InetAddress.getLocalHost();
            name = address.getHostName();
        } catch (UnknownHostException e) {
            name = "";
        }

        return name;
    }
}

Related

  1. getAllHostIPs(String hostName)
  2. getAllInternalHostIPs(String hostName)
  3. getAllIp()
  4. getAllIPAddresses()
  5. getAllIPsAndAssignedBroadcastAddresses()
  6. getAllLocalIP()
  7. getAllLocalIP()
  8. getAllLocalIPs()
  9. getAllLocalIpv4Addresses()