List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.apporiented.hermesftp.utils.NetUtils.java
/** * Returns the machine's network address. * /*w ww . j av a 2 s . co m*/ * @param fallBackToLocalhost True if loopback address should be used if * there is no net. * @return The ip address. */ public static InetAddress getMachineAddress(boolean fallBackToLocalhost) { InetAddress result = null; try { Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); InetAddress ia = getMachineAddress(ni); if (ia != null) { result = ia; break; } } if (result == null) { result = InetAddress.getLocalHost(); } } catch (SocketException e) { log.error(e); } catch (UnknownHostException e) { log.error(e); } return result; }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
public String getHostName() { try {/*from www . j a v a2 s .c om*/ return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "unknown"; } }
From source file:ezbake.thriftrunner.starters.SimpleStarter.java
@Override public void initialize() throws IOException { if (hostName == null) { hostName = InetAddress.getLocalHost().getCanonicalHostName(); }/*from ww w . ja v a 2 s. c om*/ getFreePort(); }
From source file:com.cloudera.cdk.morphline.solr.EnvironmentTest.java
@Test public void testEnvironment() throws UnknownHostException { System.out.println("EXPECTED_SOLR_VERSION: " + EXPECTED_SOLR_VERSION); System.out.println("Running test suite with java version: " + SystemUtils.JAVA_VERSION + " " + SystemUtils.JAVA_VM_NAME + " on " + SystemUtils.OS_NAME + " " + SystemUtils.OS_VERSION + "/" + SystemUtils.OS_ARCH + " on host: " + InetAddress.getLocalHost().getHostName()); Package p = SolrCore.class.getPackage(); System.out.println("Running test suite with solr-spec-version: " + p.getSpecificationVersion() + ", solr-impl-version: " + p.getImplementationVersion()); if (EXPECTED_SOLR_VERSION != null) { assertTrue("unexpected version: " + p.getSpecificationVersion(), p.getSpecificationVersion().startsWith(EXPECTED_SOLR_VERSION)); assertTrue("unexpected version: " + p.getImplementationVersion(), p.getImplementationVersion().startsWith(EXPECTED_SOLR_VERSION)); }/*from w w w.j a v a2s . co m*/ p = LucenePackage.class.getPackage(); System.out.println("Running test suite with lucene-spec-version: " + p.getSpecificationVersion() + ", lucene-impl-version: " + p.getImplementationVersion()); if (EXPECTED_SOLR_VERSION != null) { assertTrue("unexpected version: " + p.getSpecificationVersion(), p.getSpecificationVersion().startsWith(EXPECTED_SOLR_VERSION)); assertTrue("unexpected version: " + p.getImplementationVersion(), p.getImplementationVersion().startsWith(EXPECTED_SOLR_VERSION)); Version expectedMinorLuceneVersion = getMinorLuceneVersion(EXPECTED_SOLR_VERSION); System.out.println("expectedMinorLuceneVersion: " + expectedMinorLuceneVersion); assertTrue(Version.LUCENE_CURRENT.onOrAfter(expectedMinorLuceneVersion)); } }
From source file:com.baidu.rigel.biplatform.cache.util.MacAddressUtil.java
/** * ??ip???ip?//from www . ja v a 2 s . co m * @param ia * @throws SocketException * @throws UnknownHostException */ public static String getIpAddress(InetAddress ia) throws UnknownHostException { if (ia == null) { ia = InetAddress.getLocalHost(); } return ia.getHostAddress(); }
From source file:com.mgmtp.perfload.perfmon.util.PerfMonUtils.java
/** * @return the name of the localhost, or unknown, if it cannot be retrieved. *//*w ww .j ava2 s .c o m*/ public static String getHostName() { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "unknown"; } }
From source file:com.netflix.conductor.server.ConductorConfig.java
@Override public String getServerId() { try {//from w w w. j a v a 2s. c o m return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "unknown"; } }
From source file:com.jcraft.weirdx.XRexec.java
public XRexec(String myName, int num) { try {//from www . j av a 2 s . c o m InetAddress local = null; if (myName != null && myName.length() > 0) { local = InetAddress.getByName(myName); } else { local = InetAddress.getLocalHost(); } display = local.getHostName() + ":" + num + ".0"; } catch (Exception e) { display = "localhost:" + num + ".0"; LOG.error(e); } JFrame jframe = new JFrame(); Container cpane = jframe.getContentPane(); cpane.setLayout(new GridLayout(0, 1)); JPanel jpanel = null; jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Host")); jpanel.setLayout(new BorderLayout()); host.setText(""); host.setMinimumSize(new Dimension(50, 25)); host.setEditable(true); jpanel.add(host, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("User")); jpanel.setLayout(new BorderLayout()); name.setText(""); name.setMinimumSize(new Dimension(50, 25)); name.setEditable(true); jpanel.add(name, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Password")); jpanel.setLayout(new BorderLayout()); passwd.setMinimumSize(new Dimension(50, 25)); passwd.setEditable(true); jpanel.add(passwd, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Command with Absolute Path")); jpanel.setLayout(new BorderLayout()); command.setText(""); command.setMinimumSize(new Dimension(50, 25)); command.setEditable(true); jpanel.add(command, "Center"); command.addActionListener(this); cpane.add(jpanel); jpanel = new JPanel(); jpanel.add(rexec, "Center"); rexec.addActionListener(this); cpane.add(jpanel); jframe.pack(); jframe.setVisible(true); }
From source file:org.onebusaway.webapp.actions.StatusAction.java
@Override public String execute() { Map<String, Object> configuration = _configurationService.getConfiguration(_forceRefresh, ERROR); _model.putAll(configuration);/* w w w. ja va 2s.c om*/ try { InetAddress address = InetAddress.getLocalHost(); _model.put("hostAddress", address.getHostAddress()); _model.put("hostName", address.getHostName()); } catch (Exception ex) { _log.warn("error determining hostname", ex); } return SUCCESS; }
From source file:org.auraframework.test.configuration.JettyTestServletConfig.java
public JettyTestServletConfig() throws Exception { String host;//www . j a v a 2 s. c o m int port; boolean spawnJetty = Boolean.parseBoolean(System.getProperty("jetty.spawn", "false")); if (spawnJetty) { Server server = AuraJettyServer.getInstance(); Connector connector = server.getConnectors()[0]; port = connector.getPort(); host = connector.getHost(); if (host == null) { try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { host = "localhost"; } } System.out.println(String.format("Starting Jetty on %s:%s", host, port)); server.start(); } else { port = Integer.parseInt(System.getProperty("jetty.port", "9090")); host = System.getProperty("jetty.host"); if (host == null) { try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { host = "localhost"; } } } baseUrl = new URL("http", host, port, "/"); System.out.println(String.format("BaseUrl: %s", baseUrl)); }