Java IP Address Get getLocalHostIps()

Here you can find the source of getLocalHostIps()

Description

get Local Host Ips

License

Apache License

Declaration

public static String getLocalHostIps() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static String localHostIps = "";

    public static String getLocalHostIps() {
        if (localHostIps.equals("")) {
            StringBuffer sb = new StringBuffer();
            InetAddress[] ias;//from   www.j  a va  2  s.c  o m
            try {
                ias = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
                for (int i = 0; i < ias.length; i++) {
                    String ip = ias[i].getHostAddress();
                    sb.append(ip);
                    sb.append(",");
                }
                localHostIps = sb.toString();
            } catch (UnknownHostException e) {
                localHostIps = "";
            }
        }
        return localHostIps;
    }
}

Related

  1. getLocalHostIp()
  2. getLocalhostIp()
  3. getLocalHostIp()
  4. getLocalHostIPAdress()
  5. getLocalHostIps()
  6. getLocalIp()
  7. getLocalIp()
  8. getLocalIP()
  9. getLocalIP()