List of usage examples for java.net InetAddress getHostName
public String getHostName()
From source file:edu.ku.brc.specify.utilapps.RegProcEntry.java
private void discoverHostName() { if (hostName == null) { String ip = props.getProperty("ip"); if (ip == null) { ip = ""; hostName = ""; props.put("hostname", hostName); } else {//from ww w. ja v a2 s . com hostName = ipHash.get(ip); } if (hostName == null) { try { InetAddress addr = InetAddress.getByName(ip); hostName = addr.getHostName(); ipHash.put(ip, hostName); } catch (UnknownHostException e) { e.printStackTrace(); } } props.put("hostname", hostName); } }
From source file:de.iai.ilcd.configuration.ConfigurationService.java
private void confNodeInfo() { String detectedHostName = null; try {//from ww w. j a va 2 s .co m InetAddress inetAddress = InetAddress.getLocalHost(); detectedHostName = inetAddress.getHostName(); } catch (UnknownHostException e) { this.logger.error("Could not detect hostname", e); } String configuredHostName = this.fileConfig.getString("service.url.hostname"); int port = this.fileConfig.getInteger("service.url.port", 80); String hostName; if (configuredHostName != null) { hostName = configuredHostName; } else { hostName = detectedHostName; } try { URI newUri = new URI("http", null, hostName, (port == 80 ? -1 : port), this.contextPath, null, null); this.logger.info("application base URI: " + newUri.toString()); this.baseURI = newUri; this.nodeInfo.setBaseURL(newUri.toString() + "/resource/"); } catch (URISyntaxException e) { throw new RuntimeException("FATAL ERROR: could not determine base URL for service interface", e); } try { this.nodeInfo.setNodeID(this.fileConfig.getString("service.node.id")); } catch (Exception e) { this.logger.error("Cannot set nodeid from configuration file", e); } try { this.nodeInfo.setName(this.fileConfig.getString("service.node.name")); } catch (Exception e) { this.logger.error("Cannot set nodename from configuration file", e); } this.nodeInfo.setOperator(this.fileConfig.getString("service.node.operator")); this.nodeInfo.setDescription(this.fileConfig.getString("service.node.description")); // override baseURL only if it is explicitly set in the configuration file if (this.fileConfig.getString("service.node.baseURL") != null) { String url = this.fileConfig.getString("service.node.baseURL"); if (!url.endsWith("/")) url += "/"; this.nodeInfo.setBaseURL(url); } this.nodeInfo.setAdminName(this.fileConfig.getString("service.admin.name")); this.nodeInfo.setAdminEMail(this.fileConfig.getString("service.admin.email")); this.nodeInfo.setAdminPhone(this.fileConfig.getString("service.admin.phone")); this.nodeInfo.setAdminWWW(this.fileConfig.getString("service.admin.www")); }
From source file:net.lightbody.bmp.proxy.jetty.http.ajp.AJP13Listener.java
/** * Handle Job. Implementation of ThreadPool.handle(), calls * handleConnection./*from www. j av a 2 s. c om*/ * * @param socket * A Connection. */ public void handleConnection(Socket socket) throws IOException { // Check acceptable remote servers if (_remoteServers != null && _remoteServers.length > 0) { boolean match = false; InetAddress inetAddress = socket.getInetAddress(); String hostAddr = inetAddress.getHostAddress(); String hostName = inetAddress.getHostName(); for (int i = 0; i < _remoteServers.length; i++) { if (hostName.equals(_remoteServers[i]) || hostAddr.equals(_remoteServers[i])) { match = true; break; } } if (!match) { log.warn("AJP13 Connection from un-approved host: " + inetAddress); return; } } // Handle the connection socket.setTcpNoDelay(true); socket.setSoTimeout(getMaxIdleTimeMs()); AJP13Connection connection = createConnection(socket); try { connection.handle(); } finally { connection.destroy(); } }
From source file:nl.vu.psy.rite.Rite.java
private Rite() { version = Rite.class.getPackage().getImplementationVersion(); StringTokenizer st = null;/*from www . j a v a 2s .c om*/ if (version != null) { st = new StringTokenizer(version, "_"); } else { st = new StringTokenizer(""); version = "undetermined"; } System.out.println(); System.out.println("+-++-++-++-+"); System.out.print("|R||i||t||e|"); if (version != null && st.countTokens() >= 2) { System.out.print(" version: " + st.nextToken() + " build " + st.nextToken() + "\n"); } else { System.out.print(" version: " + version + "\n"); } System.out.println("+-++-++-++-+"); System.out.println(); properties = new Properties(); try { properties.load(new FileInputStream(new File(PROPERTIES))); } catch (Exception e1) { // Absorb System.out.println( "Could not read properties files. Assuming programmed default values for client settings."); } identifier = getProperty(PropertyKeys.ID); System.out.println("Rite identifier: " + identifier); startDate = new Date(); long appLife = Long.parseLong(getProperty(PropertyKeys.LIFETIME)); endDate = new Date(startDate.getTime() + appLife); System.out.println("Application start time: " + TimeStamp.dateToString(startDate)); System.out.println("Configured application end time: " + TimeStamp.dateToString(endDate)); System.out.println("Setting up file cache..."); // TODO make file cache optional // Set up file cache try { fileCache = new FileCache(getProperty(PropertyKeys.RELIC)); } catch (RiteException e) { System.out.println("Could not set up file cache: " + e.getMessage()); run = false; } // Initialize info struct System.out.println("Initializing client info..."); ClientInfo info = new ClientInfo(); info.setClientId(identifier); try { InetAddress addr = InetAddress.getLocalHost(); String host = addr.getHostName(); info.setClientHost(host); } catch (UnknownHostException e) { info.setClientHost("Unknown: " + e.getMessage()); } info.setClientStart(startDate); info.setWorkingDirectory(new File(System.getProperty("user.dir"))); System.out.println("Configuring host connection..."); rh = null; try { boolean listfiles = Boolean.parseBoolean(getProperty(PropertyKeys.LISTFILES)); rh = new Host(getProperty(PropertyKeys.HOST), info, listfiles); } catch (RiteException e) { System.out.println("Could not connect to the rite host: " + e.getMessage()); run = false; } // Set up recipecooker recipeTimer = new Timer("recipeTimer", false); recipeCooker = new RecipeCooker(); long tickRate = Long.parseLong(getProperty(PropertyKeys.TICK)); recipeTimer.scheduleAtFixedRate(recipeCooker, 1000, tickRate); }
From source file:info.pancancer.arch3.reporting.Arch3ReportImpl.java
@Override public Map<String, String> getEnvironmentMap() { Map<String, String> env = new TreeMap<>(); env.put("version", this.getClass().getPackage().getImplementationVersion()); try {/* w ww .ja v a2 s.c o m*/ Constants constantsInstance = new Constants(); Class constants = Class.forName("info.pancancer.arch3.utils.Constants"); Field[] declaredFields = constants.getDeclaredFields(); for (Field field : declaredFields) { if (field.getName().contains("PASSWORD")) { continue; } String settingKey = field.get(constantsInstance).toString(); if (this.settings.containsKey(settingKey)) { env.put(settingKey, this.settings.getString(settingKey)); } } } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } catch (IllegalArgumentException | IllegalAccessException ex) { throw new RuntimeException(ex); } try { // stolen from stack overflow URL whatismyip = new URL("http://checkip.amazonaws.com"); String ip; try (BufferedReader in = new BufferedReader( new InputStreamReader(whatismyip.openStream(), StandardCharsets.UTF_8))) { ip = in.readLine(); // you get the IP as a String } // reverse ip address InetAddress addr = InetAddress.getByName(ip); env.put("canonical_host_name", addr.getCanonicalHostName()); env.put("host_name", addr.getHostName()); } catch (IOException e) { System.out.println("Could not lookup ip address of self"); } return env; }
From source file:com.googlecode.jmxtrans.model.output.OpenTSDBGenericWriterTests.java
/** * Confirm operation when the host tag is enabled, but the local hostname is not known. *///from ww w . j ava 2 s. c o m @Test @Ignore("issue with classloader used by powermockito and the securityManager which use ClassLoader.getResource") public void testNullHostTagname() throws Exception { // Prepare. InetAddress mockInetAddress = Mockito.mock(InetAddress.class); PowerMockito.mockStatic(InetAddress.class); PowerMockito.when(InetAddress.getLocalHost()).thenReturn(mockInetAddress); Mockito.when(mockInetAddress.getHostName()).thenReturn(null); OpenTSDBGenericWriter writer = createWriter("addHostnameTag", true); // Execute. writer.start(); writer.doWrite(null, this.mockQuery, ImmutableList.of(this.mockResult)); // Validate. Assert.assertFalse(this.tvMetricLinesSent.get(0).matches(".*\\bhost=.*")); // Ensure host tag is excluded }
From source file:com.jkoolcloud.tnt4j.utils.Utils.java
/** * Resolves the specified IP Address to a host name. If no IP Address is * given, then resolves local host name. * * @param hostIp//from w w w . j a va 2 s . c o m * host IP Address to resolve * @return host name */ public static String resolveAddressToHostName(byte[] hostIp) { String hostName = null; InetAddress host; try { if (hostIp == null || hostIp.length == 0) host = InetAddress.getLocalHost(); else host = InetAddress.getByAddress(hostIp); hostName = host.getHostName(); } catch (UnknownHostException e) { } return hostName; }
From source file:de.fischer.thotti.core.runner.NDRunner.java
public String getHostname() { try {/*from www . jav a2s . c o m*/ InetAddress localMachine = InetAddress.getLocalHost(); return localMachine.getHostName(); } catch (java.net.UnknownHostException uhe) { return null; } }
From source file:edu.vt.middleware.gator.log4j.JdbcConfigurator.java
/** * Gets first project to which the host possessing the given IP address is a * member.//from w w w.ja va 2 s . co m * * @param addr IP address. * * @return First project to which the client at the given IP address is a * member. * * @throws UnauthorizedClientException If given client is not a member of * any projects. */ private ProjectConfig getProject(final InetAddress addr) throws UnauthorizedClientException { final Set<ProjectConfig> projects = new HashSet<ProjectConfig>(); // Add projects that contain the given client by host or IP address projects.addAll(configManager.findProjectsByClientName(addr.getHostAddress())); projects.addAll(configManager.findProjectsByClientName(addr.getHostName())); if (projects.size() > 0) { return projects.iterator().next(); } else { throw new UnauthorizedClientException(addr, String.format("%s not registered with any projects.", addr)); } }
From source file:org.smartfrog.avalanche.client.sf.apps.gt4.security.GridSecurity.java
public void reqHostCert(String hostName, Properties props) throws GT4SecurityException { try {/* w w w . j ava2s . co m*/ if (null == hostName) { log.info("Host name is not provided... "); log.info("Getting host name from the system..."); InetAddress addr = InetAddress.getLocalHost(); String hostname = addr.getHostName(); } } catch (UnknownHostException ue) { log.info(ue); throw new GT4SecurityException("Error getting hostname...", ue); } if (null == props) { props = new Properties(); } props.setProperty("-host", hostName); CertUtils utils = new CertUtils(globusLoc); //utils.gridCertReq(props); utils.gridCertReq(props, null); }