Java Host Address Get getHostAddress()

Here you can find the source of getHostAddress()

Description

get Host Address

License

Apache License

Declaration

public static String getHostAddress() throws UnknownHostException 

Method Source Code


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

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static String getHostAddress() throws UnknownHostException {
        try {// w w w .  j  a  v a 2  s.  c om
            return (InetAddress.getLocalHost()).getHostAddress();
        } catch (UnknownHostException uhe) {
            String host = uhe.getMessage();
            if (host != null) {
                int colon = host.indexOf(':');
                if (colon > 0) {
                    return host.substring(0, colon);
                }
            }
            throw uhe;
        }
    }
}

Related

  1. getHostAddress()
  2. getHostAddress()
  3. getHostAddress()
  4. getHostAddress()
  5. getHostAddress()
  6. getHostAddress(boolean promiscuous)
  7. getHostAddress(final String name)
  8. getHostAddress(String hostname)
  9. getHostAddress(String hostPort)