List of usage examples for java.net InetAddress getAllByName
public static InetAddress[] getAllByName(String host) throws UnknownHostException
From source file:lcmc.ArgumentParser.java
/** Sets user config from command line options returns host, for which dns lookup failed. */ private String setUserConfigFromOptions(final Map<String, List<HostOptions>> clusters) { final Map<String, List<Host>> hostMap = new LinkedHashMap<String, List<Host>>(); for (final String clusterName : clusters.keySet()) { for (final HostOptions hostOptions : clusters.get(clusterName)) { final String hostnameEntered = hostOptions.getHost(); InetAddress[] addresses = null; try { addresses = InetAddress.getAllByName(hostnameEntered); } catch (final UnknownHostException e) { }// w w w . j av a 2 s. c o m String ip = null; if (addresses != null) { if (addresses.length == 0) { LOG.debug("setUserConfigFromOptions: lookup failed"); /* lookup failed */ } else { ip = addresses[0].getHostAddress(); } } if (ip == null) { return hostnameEntered; } userConfig.setHost(hostMap, hostOptions.getLoginUser(), hostnameEntered, ip, hostOptions.getPort(), null, hostOptions.getUseSudo(), false); } } for (final String clusterName : clusters.keySet()) { final Cluster cluster = clusterProvider.get(); cluster.setName(clusterName); cluster.setSavable(false); application.addClusterToClusters(cluster); for (final HostOptions ho : clusters.get(clusterName)) { userConfig.setHostCluster(hostMap, cluster, ho.getHost(), !UserConfig.PROXY_HOST); } } return null; }
From source file:jetbrains.buildServer.clouds.azure.connector.AzureApiConnector.java
private static ArrayList<ConfigurationSet> createConfigurationSetList(int port, String serverLocation) { ArrayList<ConfigurationSet> retval = new ArrayList<ConfigurationSet>(); final ConfigurationSet value = new ConfigurationSet(); value.setConfigurationSetType(ConfigurationSetTypes.NETWORKCONFIGURATION); final ArrayList<InputEndpoint> endpointsList = new ArrayList<InputEndpoint>(); value.setInputEndpoints(endpointsList); InputEndpoint endpoint = new InputEndpoint(); endpointsList.add(endpoint);/*from w ww .j a v a 2 s. com*/ endpoint.setLocalPort(port); endpoint.setPort(port); endpoint.setProtocol("TCP"); endpoint.setName(AzurePropertiesNames.ENDPOINT_NAME); final EndpointAcl acl = new EndpointAcl(); endpoint.setEndpointAcl(acl); final URI serverUri = URI.create(serverLocation); List<InetAddress> serverAddresses = new ArrayList<InetAddress>(); try { serverAddresses.addAll(Arrays.asList(InetAddress.getAllByName(serverUri.getHost()))); serverAddresses.add(InetAddress.getLocalHost()); } catch (UnknownHostException e) { LOG.warn("Unable to identify server name ip list", e); } final ArrayList<AccessControlListRule> aclRules = new ArrayList<AccessControlListRule>(); acl.setRules(aclRules); int order = 1; for (final InetAddress address : serverAddresses) { if (!(address instanceof Inet4Address)) { continue; } final AccessControlListRule rule = new AccessControlListRule(); rule.setOrder(order++); rule.setAction("Permit"); rule.setRemoteSubnet(address.getHostAddress() + "/32"); rule.setDescription("Server"); aclRules.add(rule); } retval.add(value); return retval; }
From source file:com.archivas.clienttools.arcutils.impl.adapter.Hcap2Adapter.java
public static List<InetAddress> getHostAddresses(String hostName) throws UnknownHostException { return Arrays.asList(InetAddress.getAllByName(hostName)); }
From source file:com.edmunds.zookeeper.connection.ZooKeeperConnection.java
/** * Builds a ZooKeeper connection string based on the current configuration data. * * @return a ZooKeeper connection string * @throws java.net.UnknownHostException if the {@link #hostName} cannot be found in DNS *///from ww w . ja v a 2 s . c o m private String buildConnectString() throws UnknownHostException { Validate.notEmpty(hostName, "Host name must not be empty."); Validate.isTrue(port > 0, "Invalid port: " + port); final InetAddress[] inetAddresses = InetAddress.getAllByName(hostName); final StringBuilder connectString = new StringBuilder(); for (InetAddress inetAddress : inetAddresses) { if (inetAddress instanceof Inet4Address) { if (connectString.length() > 0) { connectString.append(","); } connectString.append(inetAddress.getHostAddress()); connectString.append(":"); connectString.append(port); } } connectString.append(pathPrefix); return connectString.toString(); }
From source file:jetbrains.buildServer.clouds.azure.asm.connector.AzureApiConnector.java
private static ArrayList<ConfigurationSet> createConfigurationSetList(int port, String serverLocation) { ArrayList<ConfigurationSet> retval = new ArrayList<>(); final ConfigurationSet value = new ConfigurationSet(); value.setConfigurationSetType(ConfigurationSetTypes.NETWORKCONFIGURATION); final ArrayList<InputEndpoint> endpointsList = new ArrayList<>(); value.setInputEndpoints(endpointsList); if (port > 0) { InputEndpoint endpoint = new InputEndpoint(); endpointsList.add(endpoint);//from ww w. ja v a 2 s .c o m endpoint.setLocalPort(port); endpoint.setPort(port); endpoint.setProtocol("TCP"); endpoint.setName(AzurePropertiesNames.ENDPOINT_NAME); final EndpointAcl acl = new EndpointAcl(); endpoint.setEndpointAcl(acl); final URI serverUri = URI.create(serverLocation); List<InetAddress> serverAddresses = new ArrayList<>(); try { serverAddresses.addAll(Arrays.asList(InetAddress.getAllByName(serverUri.getHost()))); serverAddresses.add(InetAddress.getLocalHost()); } catch (UnknownHostException e) { LOG.warn("Unable to identify server name ip list", e); } final ArrayList<AccessControlListRule> aclRules = new ArrayList<>(); acl.setRules(aclRules); int order = 1; for (final InetAddress address : serverAddresses) { if (!(address instanceof Inet4Address)) { continue; } final AccessControlListRule rule = new AccessControlListRule(); rule.setOrder(order++); rule.setAction("Permit"); rule.setRemoteSubnet(address.getHostAddress() + "/32"); rule.setDescription("Server"); aclRules.add(rule); } } retval.add(value); return retval; }
From source file:org.apache.oozie.test.XTestCase.java
private JobConf createDFSConfig() throws UnknownHostException { JobConf conf = new JobConf(); conf.set("dfs.block.access.token.enable", "false"); conf.set("dfs.permissions", "true"); conf.set("hadoop.security.authentication", "simple"); //Doing this because Hadoop 1.x does not support '*' if the value is '*,127.0.0.1' StringBuilder sb = new StringBuilder(); sb.append("127.0.0.1,localhost"); for (InetAddress i : InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())) { sb.append(",").append(i.getCanonicalHostName()); }/* ww w . ja va 2 s. c o m*/ conf.set("hadoop.proxyuser." + getOozieUser() + ".hosts", sb.toString()); conf.set("hadoop.proxyuser." + getOozieUser() + ".groups", getTestGroup()); conf.set("mapred.tasktracker.map.tasks.maximum", "4"); conf.set("mapred.tasktracker.reduce.tasks.maximum", "4"); conf.set("hadoop.tmp.dir", "target/test-data" + "/minicluster"); // Scheduler properties required for YARN CapacityScheduler to work conf.set("yarn.scheduler.capacity.root.queues", "default"); conf.set("yarn.scheduler.capacity.root.default.capacity", "100"); // Required to prevent deadlocks with YARN CapacityScheduler conf.set("yarn.scheduler.capacity.maximum-am-resource-percent", "0.5"); // Default value is 90 - if you have low disk space, tests will fail. conf.set("yarn.nodemanager.disk-health-checker.max-disk-utilization-per-disk-percentage", "99"); return conf; }
From source file:com.clustercontrol.nodemap.session.NodeMapControllerBean.java
/** * fping?ping?????<BR>/* w ww .j av a 2 s. c o m*/ * @param facilityId Ping?ID()collect?facilityID??? * @return ping?? * @throws HinemosUnknown * @throws NodeMapException */ public List<String> pingToFacilityList(List<String> facilityList) throws HinemosUnknown, NodeMapException { String message = ""; String messageOrg = ""; //?????? // hosts[] IP(String ??) // hostsv6[] IPv6(String??) // node IP???? // target nodo? HashSet<String> hosts = new HashSet<String>(); HashSet<String> hostsv6 = new HashSet<String>(); // ip?name Hashtable<String, List<String>> facilityNameTable = new Hashtable<>(); String facilityId = null; int version = 4; String[] node; for (int index = 0; index < facilityList.size(); index++) { facilityId = facilityList.get(index); if (facilityId != null && !"".equals(facilityId)) { node = new String[2]; try { // ?? NodeInfo info = new RepositoryControllerBean().getNode(facilityId); if (info.getIpAddressVersion() != null) { version = info.getIpAddressVersion(); } else { version = 4; } if (version == 6) { InetAddress[] ip = InetAddress.getAllByName(info.getIpAddressV6()); if (ip.length != 1) { //IPInetAddress??????1???????? //UnnownHostExcption UnknownHostException e = new UnknownHostException(); m_log.info("pingToFacilityList() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } node[0] = ip[0].getHostAddress(); if (node[0] != null && !node[0].equals("")) { //IPHashSet????? hostsv6.add(node[0]); } } else { node[0] = info.getIpAddressV4(); if (node[0] != null && !node[0].equals("")) { //IPHashSet????? hosts.add(node[0]); } } if (node[0] != null && !node[0].equals("")) { node[1] = info.getNodeName(); //target?????? List<String> facilitys = facilityNameTable.get(node[0]); if (facilitys == null) { facilitys = new ArrayList<>(); } facilitys.add(facilityId); facilityNameTable.put(node[0], facilitys); } } catch (FacilityNotFound e) { message = MessageConstant.MESSAGE_COULD_NOT_GET_NODE_ATTRIBUTES_PING.getMessage() + "," + facilityId; messageOrg = e.getMessage(); throw new NodeMapException(message + ", " + messageOrg, e); } catch (UnknownHostException e) { // ??? } } } int runCount = 0; int runInterval = 0; int pingTimeout = 0; try { // [](default:1?19) String runCountKey = "nodemap.ping.runcount"; runCount = HinemosPropertyUtil .getHinemosPropertyNum(runCountKey, Long.valueOf(PingRunCountConstant.TYPE_COUNT_01)) .intValue(); CommonValidator.validateInt(runCountKey, runCount, 1, 9); // [ms](default:1000?05000) String runIntervalKey = "nodemap.ping.runinterval"; runInterval = HinemosPropertyUtil .getHinemosPropertyNum(runIntervalKey, Long.valueOf(PingRunIntervalConstant.TYPE_SEC_02)) .intValue(); CommonValidator.validateInt(runIntervalKey, runInterval, 0, 5 * 1000); // [ms](default:5000?13600000) String pintTimeoutKey = "nodemap.ping.timeout"; pingTimeout = HinemosPropertyUtil .getHinemosPropertyNum(pintTimeoutKey, Long.valueOf(PingRunIntervalConstant.TYPE_SEC_05)) .intValue(); CommonValidator.validateInt(pintTimeoutKey, pingTimeout, 1, 60 * 60 * 1000); } catch (Exception e) { m_log.warn("pingToFacilityList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); throw new HinemosUnknown(e.getMessage(), e); } ReachAddressFping reachabilityFping = new ReachAddressFping(runCount, runInterval, pingTimeout); boolean result = true; boolean resultTmp = true; ArrayList<String> msgErr = new ArrayList<>(); ArrayList<String> msgErrV6 = new ArrayList<>(); Hashtable<String, PingResult> fpingResultSet = new Hashtable<String, PingResult>(); Hashtable<String, PingResult> fpingResultSetV6 = new Hashtable<String, PingResult>(); RunMonitorPing monitorPing = new RunMonitorPing(); //IPv4???fping?? if (hosts.size() != 0) { result = reachabilityFping.isReachable(hosts, 4); msgErr = reachabilityFping.getM_errMsg(); } //IPv6???fping6?? if (hostsv6.size() != 0) { resultTmp = reachabilityFping.isReachable(hostsv6, 6); msgErrV6 = reachabilityFping.getM_errMsg(); } if (!result || !resultTmp) { return null; } List<String> retList = new ArrayList<>(); fpingResultSet = monitorPing.wrapUpFping(msgErr, runCount, 4); fpingResultSetV6 = monitorPing.wrapUpFping(msgErrV6, runCount, 6); //IPv4????????IPv6????? m_log.debug("pingToFacilityList(): before fpingResultSet check"); if (fpingResultSet.size() == 0) { m_log.debug("pingToFacilityList(): after fpingResultSet check"); fpingResultSet = fpingResultSetV6; } //IPv4??????IPv6?? else if (fpingResultSetV6.size() != 0) { fpingResultSet.putAll(fpingResultSetV6); } for (Map.Entry<String, List<String>> ipAdd : facilityNameTable.entrySet()) { PingResult pingResult = fpingResultSet.get(ipAdd.getKey()); for (String facility : ipAdd.getValue()) { retList.add(facility + " : " + pingResult.getMesseageOrg()); } } return retList; }
From source file:Tcpbw100.java
public void dottcp(StatusPanel sPanel) throws IOException { Socket ctlSocket = null;//from ww w. ja v a 2s . c om if (!isApplication) { /************************************************************************* * Added by Seth Peery * Instead of using the getCodeBase().getHost() value for the testing server, * which assumes this applet is being served from the web100srv server, * use a parameter provided in the APPLET tag. * Note that for this to work the applet must be signed because you are * potentially accessing a server outside the source domain. */ if (host == null) { host = getParameter("testingServer"); System.err.println("host set to " + host); } reportHost = getParameter("reportHost"); String reportPortString = getParameter("reportPort"); userId = getParameter("userId"); connectionId = getParameter("connectionId"); /************************************************************************/ /* fall back to the old behaviour if the APPLET tag is not set */ if (host == null) { host = getCodeBase().getHost(); System.err.println("host set to " + host); } pub_host = host; if (reportHost == null) { reportHost = host; } if (reportPortString == null) { reportPort = 33001; } else { reportPort = new Integer(reportPortString); } } results.append("web100srv: '" + host + "' [" + InetAddress.getByName(host) + "]\n"); int ctlport = 3001; double wait2; int sbuf, rbuf; int i, wait, swait = 0; for (int iter = 0; iter < 2; iter++) { failed = false; String actual_host = host; try { if (preferIPv6.isSelected()) { try { System.setProperty("java.net.preferIPv6Addresses", "true"); System.setProperty("java.net.preferIPv4Stack", "false"); System.err.println("java.net.preferIPv6Addresses = " + System.getProperty("java.net.preferIPv6Addresses")); System.err.println( "java.net.preferIPv4Stack = " + System.getProperty("java.net.preferIPv4Stack")); } catch (SecurityException e) { System.err.println("Couldn't set system property. Check your security settings."); } } //this disables the checkbox while measuring preferIPv6.setEnabled(false); //preferIPv6Addresses does not seem to do anything . //So I'll try a different approach if (preferIPv6.isSelected()) { outerloop: for (InetAddress addr : InetAddress.getAllByName(host)) { System.err.println(host + " resolves to " + addr.getHostAddress()); if (addr instanceof Inet6Address) { actual_host = addr.getHostAddress(); System.err.println("host set to IPv6 address:" + actual_host); break outerloop; } } } else { System.err.println("trying with IPv6 resolving disabled, using " + actual_host); } if ((InetAddress.getByName(host) instanceof Inet6Address) && (!preferIPv6.isSelected())) { System.err.println("prefer IPv6 is not selected but the host supplied is an IPv6 address"); throw new UnknownHostException("fdsfds"); } ctlSocket = new Socket(actual_host, ctlport); } catch (UnknownHostException e) { System.err.println("Don't know about host: " + actual_host); errmsg = messages.getString("unknownServer") + "\n"; failed = true; return; } catch (IOException e) { System.err.println("Couldn't get the connection to: " + actual_host + " " + ctlport); errmsg = messages.getString("serverNotRunning") + " (" + actual_host + ":" + ctlport + ")\n"; if (preferIPv6.isSelected()) { preferIPv6.setSelected(false); continue; //if preferIPv6 is true, we can try once more with false, go again at the start of the for loop } failed = true; return; } break;//if we made it here, then we need not do the for loop again } Protocol ctl = new Protocol(ctlSocket); Message msg = new Message(); /* The beginning of the protocol */ if (ctlSocket.getInetAddress() instanceof Inet6Address) { results.append(messages.getString("connected") + " " + host + messages.getString("usingIpv6") + "\n"); } else { results.append(messages.getString("connected") + " " + host + messages.getString("usingIpv4") + "\n"); } /* write our test suite request */ ctl.send_msg(MSG_LOGIN, tests); /* read the specially crafted data that kicks off the old clients */ if (ctl.readn(msg, 13) != 13) { errmsg = messages.getString("unsupportedClient") + "\n"; failed = true; return; } for (;;) { if (ctl.recv_msg(msg) != 0) { errmsg = messages.getString("protocolError") + Integer.parseInt(new String(msg.body), 16) + " instead\n"; failed = true; return; } if (msg.type != SRV_QUEUE) { errmsg = messages.getString("loggingWrongMessage") + "\n"; failed = true; return; } String tmpstr3 = new String(msg.body); wait = Integer.parseInt(tmpstr3); System.out.println("wait flag received = " + wait); if (wait == 0) { break; } if (wait == 9988) { if (swait == 0) { errmsg = messages.getString("serverBusy") + "\n"; failed = true; return; } else { errmsg = messages.getString("serverFault") + "\n"; failed = true; return; } } if (wait == 9999) { errmsg = messages.getString("serverBusy60s") + "\n"; failed = true; return; } if (wait == 9990) { // signal from the server to see if the client is still alive ctl.send_msg(MSG_WAITING, tests); continue; } // Each test should take less than 30 seconds, so tell them 45 sec * number of // tests in the queue. wait = (wait * 45); results.append(messages.getString("otherClient") + wait + messages.getString("seconds") + ".\n"); swait = 1; } f.toBack(); ff.toBack(); if (ctl.recv_msg(msg) != 0) { errmsg = messages.getString("protocolError") + Integer.parseInt(new String(msg.body), 16) + " instead\n"; failed = true; return; } if (msg.type != MSG_LOGIN) { errmsg = messages.getString("versionWrongMessage") + "\n"; failed = true; return; } String vVersion = new String(msg.body); if (!vVersion.startsWith("v")) { errmsg = messages.getString("incompatibleVersion"); failed = true; return; } System.out.println("Server version: " + vVersion.substring(1)); if (ctl.recv_msg(msg) != 0) { errmsg = messages.getString("protocolError") + Integer.parseInt(new String(msg.body), 16) + " instead\n"; failed = true; return; } if (msg.type != MSG_LOGIN) { errmsg = messages.getString("testsuiteWrongMessage") + "\n"; failed = true; return; } StringTokenizer tokenizer = new StringTokenizer(new String(msg.body), " "); while (tokenizer.hasMoreTokens()) { if (sPanel.wantToStop()) { ctl.send_msg(MSG_ERROR, "Manually stopped by the user".getBytes()); ctl.close(); ctlSocket.close(); errmsg = "\n" + messages.getString("stopped") + "\n"; failed = true; return; } int testId = Integer.parseInt(tokenizer.nextToken()); switch (testId) { case TEST_MID: sPanel.setText(messages.getString("middlebox")); simple_progressBar.setValue(1); simple_progressBar.setString(res.getString("step1")); progress_completed = 10; if (test_mid(ctl)) { results.append(errmsg); results.append(messages.getString("middleboxFail2") + "\n"); tests &= (~TEST_MID); } break; case TEST_SFW: sPanel.setText(messages.getString("simpleFirewall")); simple_progressBar.setValue(2); simple_progressBar.setString(res.getString("step2")); progress_completed = 20; if (test_sfw(ctl)) { results.append(errmsg); results.append(messages.getString("sfwFail") + "\n"); tests &= (~TEST_SFW); } break; case TEST_C2S: sPanel.setText(messages.getString("c2sThroughput")); simple_progressBar.setValue(4); simple_progressBar.setString(res.getString("step3")); progress_completed = 40; if (test_c2s(ctl)) { results.append(errmsg); results.append(messages.getString("c2sThroughputFailed") + "\n"); tests &= (~TEST_C2S); } break; case TEST_S2C: sPanel.setText(messages.getString("s2cThroughput")); simple_progressBar.setValue(7); simple_progressBar.setString(res.getString("step4")); progress_completed = 70; if (test_s2c(ctl, ctlSocket)) { results.append(errmsg); results.append(messages.getString("s2cThroughputFailed") + "\n"); tests &= (~TEST_S2C); } break; case TEST_META: System.err.println("testing meta!!"); sPanel.setText(messages.getString("meta")); if (test_meta(ctl, isApplication ? app_id : applet_id)) { results.append(errmsg); results.append(messages.getString("metaFailed") + "\n"); tests &= (~TEST_META); } break; default: errmsg = messages.getString("unknownID") + "\n"; failed = true; return; } } if (sPanel.wantToStop()) { ctl.send_msg(MSG_ERROR, "Manually stopped by the user".getBytes()); ctl.close(); ctlSocket.close(); errmsg = messages.getString("stopped") + "\n"; failed = true; return; } sPanel.setText(messages.getString("receiving")); i = 0; try { for (;;) { if (ctl.recv_msg(msg) != 0) { errmsg = messages.getString("protocolError") + Integer.parseInt(new String(msg.body), 16) + " instead\n"; failed = true; return; } if (msg.type == MSG_LOGOUT) { break; } if (msg.type != MSG_RESULTS) { errmsg = messages.getString("resultsWrongMessage") + "\n"; failed = true; return; } tmpstr += new String(msg.body); i++; } } catch (IOException e) { } if (i == 0) { results.append(messages.getString("resultsTimeout") + "\n"); } System.err.println("Calling InetAddress.getLocalHost() twice"); try { diagnosis.append(messages.getString("client") + ": " + InetAddress.getLocalHost() + "\n"); } catch (SecurityException e) { diagnosis.append(messages.getString("client") + ": 127.0.0.1\n"); results.append(messages.getString("unableToObtainIP") + "\n"); System.err.println("Unable to obtain local IP address: using 127.0.0.1"); } try { emailText += messages.getString("client") + ": " + InetAddress.getLocalHost() + "\n%0A"; } catch (SecurityException e) { emailText += messages.getString("client") + ": " + "127.0.0.1" + "\n%0A"; } ctl.close(); ctlSocket.close(); try { testResults(tmpstr); } catch (Exception ex) { results.append(messages.getString("resultsParseError") + "\n"); results.append(ex + "\n"); } if ((tests & TEST_MID) == TEST_MID) { middleboxResults(tmpstr2); } pub_isReady = "yes"; pub_errmsg = "All tests completed OK."; pub_status = "done"; }
From source file:com.zimbra.cs.util.ProxyConfOverride.java
public static InetAddress getLookupTargetIPbyIPMode(String hostname) throws ProxyConfException { InetAddress[] ips;/*from w w w. ja v a 2 s.c o m*/ try { ips = InetAddress.getAllByName(hostname); } catch (UnknownHostException e) { throw new ProxyConfException("the lookup target " + hostname + " can't be resolved"); } IPModeEnablerVar.IPMode mode = IPModeEnablerVar.getZimbraIPMode(); if (mode == IPModeEnablerVar.IPMode.IPV4_ONLY) { for (InetAddress ip : ips) { if (ip instanceof Inet4Address) { return ip; } } throw new ProxyConfException( "Can't find valid lookup target IPv4 address when zimbra IP mode is IPv4 only"); } else if (mode == IPModeEnablerVar.IPMode.IPV6_ONLY) { for (InetAddress ip : ips) { if (ip instanceof Inet6Address) { return ip; } } throw new ProxyConfException( "Can't find valid lookup target IPv6 address when zimbra IP mode is IPv6 only"); } else { for (InetAddress ip : ips) { if (ip instanceof Inet4Address) { return ip; } } return ips[0]; // try to return an IPv4, but if there is none, // simply return the first IPv6 } }