List of usage examples for java.net InetAddress getByName
public static InetAddress getByName(String host) throws UnknownHostException
From source file:edu.tcu.gaduo.ihe.iti.ct_transaction.service.NTPClient.java
public Date processResponse(String host) { TimeInfo info = null;// w w w . ja va 2 s . co m try { NTPUDPClient client = new NTPUDPClient(); client.setDefaultTimeout(10000); client.open(); InetAddress hostAddr = InetAddress.getByName(host); info = client.getTime(hostAddr); client.close(); } catch (NullPointerException e) { logger.info(e.toString()); return null; } catch (IOException e) { logger.info(e.toString()); e.printStackTrace(); return null; } message = info.getMessage(); stratum = message.getStratum(); // if (stratum <= 0) refType = "(??)"; else if (stratum == 1) refType = "(??; e.g., GPS)"; // GPS, radio clock, else refType = "(??; e.g. via NTP or SNTP)"; // stratum should be 0..15... logger.info(" Stratum: " + stratum + " " + refType); this.setRefNtpTime(message.getReferenceTimeStamp()); // Originate Time is time request sent by client (t1) this.setOrigNtpTime(message.getOriginateTimeStamp()); // Receive Time is time request received by server (t2) this.setRcvNtpTime(message.getReceiveTimeStamp()); // Transmit time is time reply sent by server (t3) this.setXmitNtpTime(message.getTransmitTimeStamp()); // Destination time is time reply received by client (t4) long destTime = info.getReturnTime(); this.setDestNtpTime(TimeStamp.getNtpTime(destTime)); info.computeDetails(); // compute offset/delay if not already done Long offsetValue = info.getOffset(); Long delayValue = info.getDelay(); this.setDelay(delay = (delayValue == null) ? "N/A" : delayValue.toString()); this.setOffset((offsetValue == null) ? "N/A" : offsetValue.toString()); Date Date = message.getReferenceTimeStamp().getDate(); return Date; }
From source file:com.madadipouya.neatgeoip.service.MaxMindServiceImpl.java
private CityResponse lookup(String ip) { try {// w ww.j a va2 s .c om return getReader().city(InetAddress.getByName(ip)); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (GeoIp2Exception e) { e.printStackTrace(); } return null; }
From source file:com.punyal.medusaserver.californiumServer.core.MedusaValidation.java
public static Client check(String medusaServerAddress, String myTicket, String ticket) { CoapClient coapClient = new CoapClient(); Logger.getLogger("org.eclipse.californium.core.network.CoAPEndpoint").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.EndpointManager").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.stack.ReliabilityLayer").setLevel(Level.OFF); CoapResponse response;/*from w ww. j a va 2 s . co m*/ coapClient.setURI(medusaServerAddress + "/" + MEDUSA_SERVER_VALIDATION_SERVICE_NAME); JSONObject json = new JSONObject(); json.put(JSON_MY_TICKET, myTicket); json.put(JSON_TICKET, ticket); response = coapClient.put(json.toString(), 0); if (response != null) { //System.out.println(response.getResponseText()); try { json.clear(); json = (JSONObject) JSONValue.parse(response.getResponseText()); long expireTime = (Long) json.get(JSON_TIME_TO_EXPIRE) + (new Date()).getTime(); String userName = json.get(JSON_USER_NAME).toString(); String[] temp = json.get(JSON_ADDRESS).toString().split("/"); String address; if (temp[1] != null) address = temp[1]; else address = "0.0.0.0"; Client client = new Client(InetAddress.getByName(address), userName, null, UnitConversion.hexStringToByteArray(ticket), expireTime); return client; } catch (Exception e) { } } else { // TODO: take } return null; }
From source file:io.selendroid.server.SelendroidStandaloneServer.java
private static URI remoteUri(int port) { try {/* ww w.j ava 2s . co m*/ InetAddress address = InetAddress.getByName("0.0.0.0"); return new URI("http://" + address.getHostAddress() + (port == 80 ? "" : (":" + port)) + "/"); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("can not create URI from HostAddress", e); } }
From source file:com.neophob.sematrix.core.output.ArtnetDevice.java
/** * //from w w w . j a v a 2 s. c om * @param controller */ public ArtnetDevice(ApplicationConfigurationHelper ph, int nrOfScreens) { super(OutputDeviceEnum.ARTNET, ph, 8, nrOfScreens); this.displayOptions = ph.getArtNetDevice(); //Get dmx specific config this.pixelsPerUniverse = ph.getArtNetPixelsPerUniverse(); try { this.targetAdress = InetAddress.getByName(ph.getArtNetIp()); this.firstUniverseId = ph.getArtNetStartUniverseId(); calculateNrOfUniverse(); this.artnet = new ArtNet(); String broadcastAddr = ph.getArtNetBroadcastAddr(); if (StringUtils.isBlank(broadcastAddr)) { broadcastAddr = ArtNetServer.DEFAULT_BROADCAST_IP; } LOG.log(Level.INFO, "Initialize ArtNet device IP: {0}, broadcast IP: {1}, Port: {2}", new Object[] { this.targetAdress.toString(), broadcastAddr, ArtNetServer.DEFAULT_PORT }); this.artnet.init(); this.artnet.setBroadCastAddress(broadcastAddr); this.artnet.start(); this.artnet.getNodeDiscovery().addListener(this); this.artnet.startNodeDiscovery(); this.initialized = true; LOG.log(Level.INFO, "ArtNet device initialized, use " + this.displayOptions.size() + " panels"); } catch (BindException e) { LOG.log(Level.WARNING, "\nFailed to initialize ArtNet device:", e); LOG.log(Level.WARNING, "Make sure no ArtNet Tools like DMX-Workshop are running!\n\n"); } catch (Exception e) { LOG.log(Level.WARNING, "Failed to initialize ArtNet device:", e); } }
From source file:com.linuxbox.enkive.importer.AbstractMessageImporter.java
public AbstractMessageImporter(String host, String port) throws UnknownHostException { this(InetAddress.getByName(host), Integer.parseInt(port)); }
From source file:ElasticSearchConnection.java
private void setupELK() { try {// www .j av a2s. c om client = TransportClient.builder().build().addTransportAddress( new InetSocketTransportAddress(InetAddress.getByName(getHostname()), getPort())); connected = true; } catch (UnknownHostException e) { e.printStackTrace(); } if (isConnected()) { try { setIndex(); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } else { System.out.println("unable to find elasticsearch server on host " + hostname + " on port " + port); } }
From source file:com.clustercontrol.port.protocol.ReachAddressTCP.java
/** * ????????????// w w w. j a v a 2 s.co m * * @param addressText * @return PORT */ @Override protected boolean isRunning(String addressText) { m_message = ""; m_messageOrg = ""; m_response = -1; boolean isReachable = false; try { long start = 0; // long end = 0; // StringBuffer bufferOrg = new StringBuffer(); // String result = ""; // Reachability ?? ICMP ?? boolean retry = true; InetAddress address = InetAddress.getByName(addressText); bufferOrg.append("Monitoring the port of " + address.getHostName() + "[" + address.getHostAddress() + "]:" + m_portNo + ".\n\n"); // Socket socket = null; for (int i = 0; i < m_sentCount && retry; i++) { try { // ? socket = new Socket(); InetSocketAddress isa = new InetSocketAddress(address, m_portNo); bufferOrg.append(HinemosTime.getDateString() + " Tried to Connect: "); start = HinemosTime.currentTimeMillis(); socket.connect(isa, m_timeout); end = HinemosTime.currentTimeMillis(); m_response = end - start; if (m_response > 0) { if (m_response < m_timeout) { result = ("Response Time = " + m_response + "ms"); } else { m_response = m_timeout; result = ("Response Time = " + m_response + "ms"); } } else { result = ("Response Time < 1ms"); } retry = false; isReachable = true; } catch (BindException e) { result = (e.getMessage() + "[BindException]"); retry = true; isReachable = false; } catch (ConnectException e) { result = (e.getMessage() + "[ConnectException]"); retry = false; isReachable = false; } catch (NoRouteToHostException e) { result = (e.getMessage() + "[NoRouteToHostException]"); retry = true; isReachable = false; } catch (PortUnreachableException e) { result = (e.getMessage() + "[PortUnreachableException]"); retry = true; isReachable = false; } catch (IOException e) { result = (e.getMessage() + "[IOException]"); retry = true; isReachable = false; } finally { bufferOrg.append(result + "\n"); if (socket != null) { try { socket.close(); } catch (IOException e) { m_log.warn("isRunning(): " + "socket close failed: " + e.getMessage(), e); } } } if (i < m_sentCount - 1 && retry) { try { Thread.sleep(m_sentInterval); } catch (InterruptedException e) { break; } } } m_message = result + "(TCP/" + m_portNo + ")"; m_messageOrg = bufferOrg.toString(); return isReachable; } catch (UnknownHostException e) { m_log.debug("isRunning(): " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage() + e.getMessage()); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage() + " (" + e.getMessage() + ")"; return false; } }
From source file:com.l2jfree.mmocore.network.SelectorThread.java
public final void openServerSocket(String address, int port) throws IOException { openServerSocket(InetAddress.getByName(address), port); }
From source file:co.cask.cdap.security.server.ExternalAuthenticationServerSSLTest.java
@BeforeClass public static void beforeClass() throws Exception { URL certUrl = ExternalAuthenticationServerSSLTest.class.getClassLoader().getResource("cert.jks"); Assert.assertNotNull(certUrl);//from ww w.ja v a 2s. co m String authHandlerConfigBase = Constants.Security.AUTH_HANDLER_CONFIG_BASE; CConfiguration cConf = CConfiguration.create(); SConfiguration sConf = SConfiguration.create(); cConf.set(Constants.Security.AUTH_SERVER_BIND_ADDRESS, "127.0.0.1"); cConf.set(Constants.Security.SSL_ENABLED, "true"); cConf.set(Constants.Security.AuthenticationServer.SSL_PORT, "0"); cConf.set(authHandlerConfigBase.concat("useLdaps"), "true"); cConf.set(authHandlerConfigBase.concat("ldapsVerifyCertificate"), "false"); sConf.set(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PATH, certUrl.getPath()); configuration = cConf; sConfiguration = sConf; String keystorePassword = sConf.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PASSWORD); KeyStoreKeyManager keyManager = new KeyStoreKeyManager(certUrl.getFile(), keystorePassword.toCharArray()); SSLUtil sslUtil = new SSLUtil(keyManager, new TrustAllTrustManager()); ldapListenerConfig = InMemoryListenerConfig.createLDAPSConfig("LDAP", InetAddress.getByName("127.0.0.1"), ldapPort, sslUtil.createSSLServerSocketFactory(), sslUtil.createSSLSocketFactory()); setup(); }