Java IP Address Get getLocalHostIPAdress()

Here you can find the source of getLocalHostIPAdress()

Description

Get Local IP Address

License

Apache License

Declaration

private static String getLocalHostIPAdress() 

Method Source Code

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

import java.net.InetAddress;

public class Main {
    /***//from   ww  w  .j av a  2s. c  o m
     * Get Local IP Address
     */
    private static String getLocalHostIPAdress() {
        String ipAddr = "";
        try {
            InetAddress inetAddr = InetAddress.getLocalHost();
            byte[] addr = inetAddr.getAddress();
            // Convert to dot representation

            for (int i = 0; i < addr.length; i++) {
                if (i > 0) {
                    ipAddr += ".";
                }
                ipAddr += addr[i] & 0xFF;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ipAddr;
    }
}

Related

  1. getLocalAddresses(boolean ipv4only)
  2. getLocalHostIp()
  3. getLocalHostIp()
  4. getLocalhostIp()
  5. getLocalHostIP()
  6. getLocalHostIps()
  7. getLocalHostIps()
  8. getLocalIP()
  9. getLocalIp()