Example usage for java.net InetAddress getLocalHost

List of usage examples for java.net InetAddress getLocalHost

Introduction

In this page you can find the example usage for java.net InetAddress getLocalHost.

Prototype

public static InetAddress getLocalHost() throws UnknownHostException 

Source Link

Document

Returns the address of the local host.

Usage

From source file:com.symbian.utils.cmdline.argscheckers.test.TestOpenSocketData.java

public void testAddressAndPort() {

    try {//w  w  w  . j a  v a2  s. c o  m
        lFilterUnderTest.check(InetAddress.getLocalHost().getHostAddress());
    } catch (ParseException aException) {
        fail();
    } catch (UnknownHostException e) {
        fail();
    }
}

From source file:net.dfs.server.main.ServerServicesStarter.java

/**
 * main will load the Application Context which, in-turn will load the 
 * Spring container with all the bean definitions. 
 * /*from w w  w .j  ava  2 s  .  com*/
 * @param args the parameter which is passed to the main().
 * @throws IOException 
 */
//invoked by serverUI
public static String startServer() throws IOException {

    String status = setServer(InetAddress.getLocalHost().getHostAddress());

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "net\\dfs\\server\\filespace\\creator\\spring-server.xml");
    FileLocationTracker locationTrack = (FileLocationTracker) context.getBean("hashMap");
    locationTrack.loadMap();
    log.info("Server Started");

    //TODO UI
    //TODO Save/Load HashMap
    //TODO Commenting
    //TODO Threads
    //TODO HeartBeating
    //TODO Services Restart Scene

    locationTrack.saveMap();
    return status;
}

From source file:hanulhan.spring.web.HostnameRest.java

@GET
@Produces({ MediaType.TEXT_PLAIN })//from w ww .j  a  va2 s. c  o m
public String getHostname() {

    try {
        String result = InetAddress.getLocalHost().getHostName();

        return result;
    } catch (Exception e) {
        LOGGER.log(Level.ERROR, "Can't process /rest/Hostname/" + e);
        return null;
    }

}

From source file:com.commercehub.dropwizard.logging.LogstashEventLayoutFactory.java

public LogstashEventLayout build() {
    LogstashEventLayout layout = new LogstashEventLayout();
    if (host != null && !host.trim().isEmpty()) {
        layout.setHost(host);/* www.j av  a  2  s  .  co  m*/
    } else {
        try {
            layout.setHost(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException ignored) {
            layout.setHost("unknown");
        }
    }
    layout.setUserFields(userFields);
    return layout;
}

From source file:org.jspringbot.keyword.util.GetLocalHostName.java

@Override
public Object execute(Object[] params) throws UnknownHostException {
    return InetAddress.getLocalHost().getHostName();
}

From source file:org.jspringbot.keyword.util.GetLocalHostAddress.java

@Override
public Object execute(Object[] params) throws UnknownHostException {
    return InetAddress.getLocalHost().getHostAddress();
}

From source file:net.librec.util.Systems.java

/**
 * Get IP of the System./*from  w  w w  .ja v  a 2 s  .co  m*/
 *
 * @return IP of the System
 */
public static String getIP() {
    InetAddress ip = null;
    try {
        ip = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return ip.getHostName() + "@" + ip.getHostAddress();
}

From source file:net.grinder.util.NetworkUtil.java

/**
 * Get the local host address, try to get actual IP.
 * //  w  w w  .  j a v a 2s.co m
 * @return ip form of host address
 */
public static String getLocalHostAddress() {
    InetAddress localHost = null;
    try {
        localHost = InetAddress.getLocalHost();
    } catch (Exception e) {
        LOGGER.error("Error while get localhost address", e);
    }
    if (localHost != null && !localHost.isLoopbackAddress()) {
        return localHost.getHostAddress();
    }
    return getLocalHostAddress("www.google.com", 80);
}

From source file:edu.yale.cs.hadoopdb.connector.AbstractDBRecordReader.java

/**
 * Helper method to retrieve local host name or null if not possible
 *///from  ww w.  jav a 2  s .  co  m
private static String getLocatHostAddres() {
    try {
        return InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        return null;
    }
}

From source file:com.taobao.metamorphosis.client.producer.SimpleXAMessageProducer.java

public static String getLocalhostName() {
    String property = System.getProperty(OVERWRITE_HOSTNAME_SYSTEM_PROPERTY);
    if (property != null && property.trim().length() > 0) {
        return property;
    }//w ww  .  java  2s. co  m
    try {
        return InetAddress.getLocalHost().getHostName();
    } catch (final UnknownHostException e) {
        throw new RuntimeException("unable to retrieve localhost name");
    }
}