Java Host Address Get getHostAddress(boolean promiscuous)

Here you can find the source of getHostAddress(boolean promiscuous)

Description

Returns the string "127.0.0.1".

License

Open Source License

Return

The host address as a string.

Declaration

public static String getHostAddress(boolean promiscuous) 

Method Source Code

//package com.java2s;
/*/*from   ww w  .j a  v a 2s . co  m*/
 * Copyright (C) 2003-2007 Jost Boekemeier
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    /**
     * Set to true, if the Java VM has been started with -Dphp.java.bridge.promiscuous=true;
     */
    public static boolean JAVABRIDGE_PROMISCUOUS;

    /**
     * Returns the string "127.0.0.1". If the system property "php.java.bridge.promiscuous" is "true",
     * the real host address is returned.
     *
     * @return The host address as a string.
     */
    public static String getHostAddress(boolean promiscuous) {
        String addr = "127.0.0.1";
        try {
            if (JAVABRIDGE_PROMISCUOUS || promiscuous)
                addr = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            /*ignore*/}
        return addr;
    }
}

Related

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