Java InetAddress.getLocalHost()

Syntax

InetAddress.getLocalHost() has the following syntax.

public static InetAddress getLocalHost()    throws UnknownHostException

Example

In the following code shows how to use InetAddress.getLocalHost() method.


/*from   w ww .  j av a 2 s.  co  m*/

import java.net.InetAddress;

public class Main {

  public static void main(String[] args) {

    try {
      InetAddress me = InetAddress.getLocalHost();
      String dottedQuad = me.getHostAddress();
      System.out.println("My address is " + dottedQuad);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder