Java Local Address Get getLocalAddress()

Here you can find the source of getLocalAddress()

Description

Gets the local address.

License

Open Source License

Return

the local address (or empty if error)

Declaration

public static String getLocalAddress() 

Method Source Code

//package com.java2s;
/*******************************************************
 *                                                     *
 * Copyright (C) 2011 Yahoo! Inc. All Rights Reserved. *
 *                                                     *
 *                Licensed under the New               *
 *                 BSD License. See the                *
 *              accompanying LICENSE file              *
 *              for the specific language              *
 *              governing permissions and              *
 *                limitations under the                *
 *                       License.                      *
 *******************************************************/

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

public class Main {
    /**//from w w  w  .ja  v  a 2s .c o m
     * Gets the local address.
     * 
     * @return the local address (or empty if error)
     */
    public static String getLocalAddress() {
        try {
            InetAddress localMachine = InetAddress.getLocalHost();
            return localMachine.getHostAddress();
        } catch (UnknownHostException uhe) {
            return "";
        }
    }
}

Related

  1. getLocalAddr()
  2. getLocalAddr()
  3. getLocalAddress()
  4. getLocalAddress()
  5. getLocalAddress()
  6. getLocalAddress()
  7. getLocalAddress()
  8. getLocalAddress()