List of usage examples for java.net InetAddress getHostName
public String getHostName()
From source file:org.openadaptor.util.NetUtil.java
public static String getLocalHostname() { String result = "<Unknown>"; InetAddress inetAddr = getLocalInetAddress(); if (inetAddr != null) { result = inetAddr.getHostName(); }//from w ww.j ava 2 s.c o m return result; }
From source file:com.lecaddyfute.utils.security.AESCrypto.java
public static Key generateKey() throws Exception { String cle = CLE;/*from ww w . j a va 2 s. c o m*/ try { if (cle.isEmpty()) { InetAddress adrLocale; adrLocale = InetAddress.getLocalHost(); cle = adrLocale.getHostName(); } if (cle.length() > 16) { cle = cle.substring(0, 16); } if (cle.length() < 16) { int chartocomplete = 16 - cle.length(); for (int i = 0; i < chartocomplete; i++) { cle = cle + i; } } logger.log(Level.INFO, "cle par defaut {0}", cle); keyValue = cle.getBytes(); } catch (Exception e) { e.printStackTrace(); } Key key = new SecretKeySpec(keyValue, ALGO); return key; }
From source file:Main.java
public static String shortName(InetAddress hostname) { if (hostname == null) return null; StringBuilder sb = new StringBuilder(); if (resolve_dns) sb.append(hostname.getHostName()); else/*from ww w . j ava 2 s . c om*/ sb.append(hostname.getHostAddress()); return sb.toString(); }
From source file:Main.java
public static String getLocalIpAddress() throws Exception { String ipAddress = null;/*from www. j a v a 2 s . c o m*/ Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface e = en.nextElement(); Enumeration<InetAddress> addresses = e.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) { ipAddress = address.getHostName(); break; } } } if (ipAddress == null) { ipAddress = InetAddress.getLocalHost().getHostAddress(); } return ipAddress; }
From source file:fr.gouv.finances.dgfip.xemelios.common.NetAccess.java
public static HttpClient getHttpClient(PropertiesExpansion applicationProperties) throws DataConfigurationException { String proxyHost = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_SERVER); String proxyPort = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PORT); String proxyUser = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_USER); String sTmp = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PASSWD); String proxyPasswd = sTmp != null ? Scramble.unScramblePassword(sTmp) : null; int intProxyPort = 0; if (proxyPort != null) { try {/*from w ww.j a v a2 s. co m*/ intProxyPort = Integer.parseInt(proxyPort); } catch (NumberFormatException nfEx) { throw new DataConfigurationException(proxyPort + " n'est pas un numro de port valide."); } } String domainName = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_DOMAIN); HttpClient client = new HttpClient(); //client.getParams().setAuthenticationPreemptive(true); // check use of this HostConfiguration hc = new HostConfiguration(); if (proxyHost != null) { hc.setProxy(proxyHost, intProxyPort); client.setHostConfiguration(hc); } if (proxyUser != null) { Credentials creds = null; if (domainName != null && domainName.length() > 0) { String hostName = "127.0.0.1"; try { InetAddress ip = InetAddress.getByName("127.0.0.1"); hostName = ip.getHostName(); } catch (Exception ex) { logger.error("", ex); } creds = new NTCredentials(proxyUser, proxyPasswd, hostName, domainName); } else { creds = new UsernamePasswordCredentials(proxyUser, proxyPasswd); } client.getState().setProxyCredentials(AuthScope.ANY, creds); // client.getState().setProxyCredentials(AuthScope.ANY,new UsernamePasswordCredentials(proxyUser,proxyPasswd)); } return client; }
From source file:HDFSFileFinder.java
private static void getBlockLocationsFromHdfs() { StringBuilder sb = new StringBuilder(); Configuration conf = new Configuration(); boolean first = true; // make connection to hdfs try {/*from ww w.j av a 2s . c o m*/ if (verbose) { writer.println("DEBUG: Trying to connect to " + fsName); } FileSystem fs = FileSystem.get(conf); Path file = new Path(fileName); FileStatus fStatus = fs.getFileStatus(file); status = fStatus; bLocations = fs.getFileBlockLocations(status, 0, status.getLen()); //print out all block locations for (BlockLocation aLocation : bLocations) { String[] names = aLocation.getHosts(); for (String name : names) { InetAddress addr = InetAddress.getByName(name); String host = addr.getHostName(); int idx = host.indexOf('.'); String hostname; if (0 < idx) { hostname = host.substring(0, host.indexOf('.')); } else { hostname = host; } if (first) { sb.append(hostname); first = false; } else { sb.append(",").append(hostname); } } } sb.append(NEWLINE); } catch (IOException e) { writer.println("Error getting block location data from namenode"); e.printStackTrace(); } writer.print(sb.toString()); writer.flush(); }
From source file:arena.utils.URLUtils.java
public static String getServerName() { String serverName = "localhost"; try {//from w ww .j a v a2 s. c om InetAddress localhost = InetAddress.getLocalHost(); serverName = localhost.getHostName(); } catch (Throwable err) { LogFactory.getLog(URLUtils.class).error("Error looking up server name", err); } return serverName; }
From source file:org.apache.kylin.tool.util.ToolUtil.java
public static String getHostName() { String hostname = System.getenv("COMPUTERNAME"); if (StringUtils.isEmpty(hostname)) { InetAddress address = null; try {/* w ww . j a v a2s .c o m*/ address = InetAddress.getLocalHost(); hostname = address.getHostName(); if (StringUtils.isEmpty(hostname)) { hostname = address.getHostAddress(); } } catch (UnknownHostException uhe) { String host = uhe.getMessage(); // host = "hostname: hostname" if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { return host.substring(0, colon); } } hostname = "Unknown"; } } return hostname; }
From source file:com.amazonaws.util.AwsHostNameUtils.java
/** * Returns the host name for the local host. If the operation is not allowed * by the security check, the textual representation of the IP address of * the local host is returned instead. If the ip address of the local host * cannot be resolved or if there is any other failure, "localhost" is * returned as a fallback.// w w w.j av a 2 s . co m */ public static String localHostName() { try { InetAddress localhost = InetAddress.getLocalHost(); return localhost.getHostName(); } catch (Exception e) { LogFactory.getLog(AwsHostNameUtils.class) .debug("Failed to determine the local hostname; fall back to " + "use \"localhost\".", e); return "localhost"; } }
From source file:ntpgraphic.PieChart.java
public static void NTPClient(String[] servers) { Properties defaultProps = System.getProperties(); //obtiene las "properties" del sistema defaultProps.put("java.net.preferIPv6Addresses", "true");//mapea el valor true en la variable java.net.preferIPv6Addresses if (servers.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from www. j av a2 s .com } Promedio = 0; Cant = 0; int j = 1; NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : servers) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info, j++); } catch (IOException ioe) { System.err.println(ioe.toString()); } } } catch (SocketException e) { System.err.println(e.toString()); } client.close(); //System.out.println("\n Pomedio "+(Promedio/Cant)); }