List of usage examples for java.net InetAddress isReachable
public boolean isReachable(int timeout) throws IOException
From source file:org.galicaster.dashboard.DashboardService.java
/** * Check the specified agent is active and reachable * @param agentName the name of the agent to check * @throws IOException if a network error occurs * @throws NotFoundException if the agent is not registered */// ww w .ja v a 2s. c om public boolean isActive(String agentName) throws NotFoundException { Agent agent = captureAgentStateService.getAgent(agentName); InetAddress addr; try { addr = InetAddress.getByName(agent.getUrl()); boolean isReachable = addr.isReachable(pingTimeout); boolean isInGoodState = true; //boolean isInGoodState = goodStates.contains(agent.getState()); logger.error("Agent {} is {}reachable{}.", new String[] { agent.getName(), isReachable ? "" : "not ", "" //isReachable ? " and reporting state " + agent.getState() : "" }); return isReachable && isInGoodState; } catch (UnknownHostException e) { // Host does not exist } catch (IOException e) { // A network error occurred, so the agent is unreachable too } return false; }
From source file:com.cnm.cnmrc.fragment.vodtvch.VodDetail.java
@Override public void onClick(View v) { // sidebar return. // 2013-12-06 comment? ? ?. // /*from w w w. jav a 2 s . c o m*/ // if (UiUtil.isSlidingMenuOpening(getActivity())) // return; // 2013-12-10 // ? . if (UiUtil.isSlidingMenuOpening(getActivity())) UiUtil.toggleSidebar(getActivity()); switch (v.getId()) { case R.id.vod_zzim: // test wifi status //boolean b = Util.setWifiEnable(getActivity(), false); // wifi check if (!Util.isWifiAvailable(getActivity())) { Toast.makeText(getActivity(), "WiFi not Available", Toast.LENGTH_SHORT).show(); break; } // STB alive check pref = CnmPreferences.getInstance(); hostAddress = pref.loadPairingHostAddress(getActivity()); // test //hostAddress = "192.168.0.6"; try { if (hostAddress.equals("")) { // 10 . Log.d("hwang", "vod : db insert"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); PopupGtvNotAlive gtvNotAlive = PopupGtvNotAlive.newInstance(vodAssetId); gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName()); break; } else { InetAddress address = InetAddress.getByName(hostAddress); boolean alive = address.isReachable(2000); if (alive) { if (startJobVodJjim) { Log.d("hwang", "don't send again"); break; // ? ??!!! } startJobVodJjim = true; Log.d("hwang", "send vod "); mVodJjimMainHandler = new VodJjimSendMassgeHandler(); // if 0, just send Cursor cursor = getActivity().getContentResolver().query(VodJjim.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.getCount() == 0) { // . vodJjimFromDb = false; TCPClientVod tcpVodClient = new TCPClientVod(mVodJjimMainHandler, hostAddress, vodAssetId); tcpVodClient.start(); } else { // ? // prepairing for send-loop vodJjimFromDb = true; getActivity().getContentResolver().registerContentObserver(VodJjim.CONTENT_URI, true, observer); // db insert Util.insertDBVodJjim(getActivity(), vodAssetId); // db insert } } cursor.close(); break; } else { // 10 . Log.d("hwang", "vod : db insert"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); PopupGtvNotAlive gtvNotAlive = PopupGtvNotAlive.newInstance(vodAssetId); gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName()); break; } } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.vod_tv_watching: // wifi check if (!Util.isWifiAvailable(getActivity())) { Toast.makeText(getActivity(), "WiFi not Available", Toast.LENGTH_SHORT).show(); break; } // STB alive check pref = CnmPreferences.getInstance(); hostAddress = pref.loadPairingHostAddress(getActivity()); // test //hostAddress = "192.168.0.6"; try { if (hostAddress.equals("")) { FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); PopupGtvNotAliveTv gtvNotAlive = new PopupGtvNotAliveTv(); gtvNotAlive.show(ft, PopupGtvNotAliveTv.class.getSimpleName()); break; } else { InetAddress address = InetAddress.getByName(hostAddress); boolean alive = address.isReachable(2000); if (alive) { if (startJobTv) { Log.d("hwang", "don't send again"); break; // ? ??!!! } startJobTv = true; mTvMainHandler = new TvSendMassgeHandler(); TCPClientTv tcpTvClient = new TCPClientTv(mTvMainHandler, hostAddress, vodAssetId); tcpTvClient.start(); break; } else { FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); PopupGtvNotAliveTv gtvNotAlive = new PopupGtvNotAliveTv(); gtvNotAlive.show(ft, PopupGtvNotAlive.class.getSimpleName()); break; } } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } }
From source file:org.rhq.plugins.netservices.PingNetServiceComponent.java
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { String addressString = resourceContext.getPluginConfiguration().getSimple(CONFIG_ADDRESS).getStringValue(); InetAddress address = InetAddress.getByName(addressString); for (MeasurementScheduleRequest request : metrics) { if (request.getName().equals("ipAddress")) { report.addData(new MeasurementDataTrait(request, address.getHostAddress())); } else if (request.getName().equals("hostName")) { report.addData(new MeasurementDataTrait(request, address.getCanonicalHostName())); } else if (request.getName().equals("responseTime")) { long start = System.currentTimeMillis(); address.isReachable(5000); report.addData(new MeasurementDataNumeric(request, (double) (System.currentTimeMillis() - start))); }//w w w . jav a2s . c o m } }
From source file:jp.primecloud.auto.process.DnsProcess.java
protected void contactHost(String ip) { long timeout = 1000L * 60 * 5; long startTime = System.currentTimeMillis(); int count = 0; boolean beforeReached = false; while (true) { try {/*from w w w .j ava 2 s . c om*/ InetAddress address = InetAddress.getByName(ip); boolean reached = address.isReachable(1500); if (reached) { if (beforeReached != reached) { count = 0; } count++; log.debug(MessageUtils.format("contactHost {0} time.(ipAddress={1})", count, ip)); if (count >= 30) { return; } } beforeReached = reached; } catch (IOException ignore) { } if (System.currentTimeMillis() - startTime > timeout) { // throw new AutoException("EPROCESS-000206", ip); } try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } }
From source file:com.clustercontrol.ping.util.ReachAddress.java
/** * ????????????// w w w. j av a 2 s . c o m * * @param addressText * @return PING */ private boolean isReachable(String addressText) { m_message = null; m_messageOrg = null; m_lost = 0; m_average = 0; try { long max = 0; long min = 0; long sum = 0; int num = 0; long start = 0; long end = 0; // StringBuffer buffer = new StringBuffer(); InetAddress address = InetAddress.getByName(addressText); buffer.append("Pinging " + address.getHostName() + " [" + address.getHostAddress() + "].\n\n"); int i = 0; for (; i < m_sentCount; i++) { // Reachability ?? ICMP ?? boolean isReachable; // isReachable????????? synchronized (m_syncObj) { start = HinemosTime.currentTimeMillis(); isReachable = address.isReachable(m_timeout); end = HinemosTime.currentTimeMillis(); } long time = end - start; if (isReachable) { buffer.append("Reply from " + address.getHostAddress() + ": "); sum += time; if (i == 0) { max = time; min = time; } else { if (time > max) { max = time; } else if (time < min) { min = time; } } num++; if (time > 0) { buffer.append("time=" + time + "ms\n"); } else { buffer.append("time<1ms\n"); } } else { if (time >= m_timeout) { buffer.append("Request timed out.\n"); } else { buffer.append( "Reply from " + address.getHostAddress() + ": Destination net unreachable.\n"); // num++; } } if (i < m_sentCount - 1) { try { Thread.sleep(m_sentInterval); } catch (InterruptedException e) { break; } } } buffer.append("\nPing statistics for " + address.getHostAddress() + ":\n"); // if (num == 0) { m_lost = 100; } else { m_lost = (i - num) * 100 / i; } // m_message = "Packets: Sent = " + i + ", Received = " + num + ", Lost = " + (i - num) + " (" + m_lost + "% loss),"; buffer.append("\t" + m_message + "\n"); buffer.append("Approximate round trip times in milli-seconds:\n"); // ? if (num != 0) { m_average = sum / num; } else { m_average = 0; } buffer.append("\tMinimum = " + min + "ms, Maximum = " + max + "ms, Average = " + m_average + "ms\n"); m_messageOrg = buffer.toString(); return true; } catch (UnknownHostException e) { m_log.warn("isReachable() " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + e.getClass().getSimpleName() + ", " + e.getMessage(), e); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + " (" + e.getMessage() + ")"; } catch (IOException e) { m_log.warn("isReachable() " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + e.getClass().getSimpleName() + ", " + e.getMessage(), e); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + " (" + e.getMessage() + ")"; } return false; }
From source file:jp.ne.sakura.kkkon.java.net.socketimpl.testapp.android.SocketImplHookTestApp.java
/** Called when the activity is first created. */ @Override//from w w w.j a va 2 s.com public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { SocketImplHookFactory.initialize(); } { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); } } } } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("ExceptionHandler"); layout.addView(tv); Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:com.intel.RtcPingDownloadTester.java
private int ping_host(String host) { InetAddress in = null; Log.v(TAG, "doInBackground"); if (!ValidateIPAddress(host)) return -1; try {/*from w w w . j a va 2s . c o m*/ Log.v(TAG, "InetAddress.getByName"); in = InetAddress.getByName(host); } catch (UnknownHostException e) { Log.v(TAG, "UnknownHostException"); return -1; } try { Log.v(TAG, "in.isReachable"); if (in.isReachable(1000)) { return 1; } else return -1; } catch (IOException e) { return -1; } }
From source file:net.itransformers.idiscover.v2.core.node_discoverers.snmpdiscoverer.SnmpSequentialNodeDiscoverer.java
@Override public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) { Map<String, String> params1 = new HashMap<String, String>(); String deviceName = connectionDetails.getParam("deviceName"); NodeDiscoveryResult result = new NodeDiscoveryResult(); if (deviceName != null && !deviceName.isEmpty()) { params1.put("deviceName", deviceName); }//www . j a v a 2s .co m String deviceType = connectionDetails.getParam("deviceType"); if (deviceType != null && !deviceType.isEmpty()) { params1.put("deviceType", deviceType); } String ipAddressStr = connectionDetails.getParam("ipAddress"); if (ipAddressStr != null && !ipAddressStr.isEmpty()) { params1.put("ipAddress", ipAddressStr); } String dnsCanonicalName = null; String dnsShortName = null; InetAddress inetAddress = null; SnmpManager snmpManager = null; Map<String, String> snmpConnParams = new HashMap<String, String>(); ResourceType snmpResource = this.discoveryResource.returnResourceByParam(params1); List<ResourceType> snmpResources = this.discoveryResource.returnResourcesByConnectionType("snmp"); String sysDescr; snmpConnParams = this.discoveryResource.getParamMap(snmpResource, "snmp"); snmpConnParams.put("ipAddress", ipAddressStr); boolean reachable; SnmpManagerCreator snmpManagerCreator = new SnmpManagerCreator(mibLoaderHolder); try { reachable = inetAddress.isReachable(Integer.parseInt(snmpConnParams.get("timeout"))); logger.info("Device with " + inetAddress.getHostAddress() + "is " + reachable); //Try first with the most probable snmp Resource snmpManager = snmpManagerCreator.create(snmpConnParams); snmpManager.init(); sysDescr = snmpGet(snmpManager, "1.3.6.1.2.1.1.1.0"); //If it does not work try with the rest if (sysDescr == null) { snmpManager.closeSnmp(); logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams); for (ResourceType resourceType : snmpResources) { snmpConnParams = this.discoveryResource.getParamMap(resourceType, "snmp"); snmpConnParams.put("ipAddress", ipAddressStr); if (!resourceType.getName().equals(snmpResource.getName())) { snmpManager = snmpManagerCreator.create(snmpConnParams); snmpManager.init(); sysDescr = snmpGet(snmpManager, "1.3.6.1.2.1.1.1.0"); if (sysDescr == null) { logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams); snmpManager.closeSnmp(); } else { deviceType = DeviceTypeResolver.getDeviceType(sysDescr); logger.info("Connected to: " + ipAddressStr + " with " + snmpConnParams); deviceName = StringUtils.substringBefore(snmpGet(snmpManager, "1.3.6.1.2.1.1.5.0"), "."); break; } } } } else { deviceType = DeviceTypeResolver.getDeviceType(sysDescr); logger.info("Connected to: " + ipAddressStr + " with " + snmpConnParams); deviceName = StringUtils.substringBefore(snmpGet(snmpManager, "1.3.6.1.2.1.1.5.0"), "."); } } catch (IOException e) { logger.error("Something went wrong in SNMP communication with " + ipAddressStr + ":Check the stacktrace \n" + e.getStackTrace()); return null; } //Despite all our efforts we got nothing from that device! if (sysDescr == null) { if (deviceName != null) { result = new NodeDiscoveryResult(deviceName, null, null); } else if (dnsCanonicalName != null) { result = new NodeDiscoveryResult(dnsShortName, null, null); } else { result = new NodeDiscoveryResult(ipAddressStr, null, null); } return result; } DiscoveryHelper discoveryHelper = discoveryHelperFactory.createDiscoveryHelper(deviceType); String[] requestParamsList = discoveryHelper.getRequestParams(discoveryTypes); Node rawDatNode = null; net.itransformers.idiscover.api.models.node_data.RawDeviceData rawData = null; try { rawDatNode = snmpManager.snmpWalk(requestParamsList); snmpManager.closeSnmp(); } catch (IOException e) { e.printStackTrace(); } if (rawDatNode != null) { SnmpXmlPrinter snmpXmlPrinter = new SnmpXmlPrinter(mibLoaderHolder.getLoader(), rawDatNode); rawData = new net.itransformers.idiscover.api.models.node_data.RawDeviceData( snmpXmlPrinter.printTreeAsXML().getBytes()); logger.trace(new String(rawData.getData())); } else { return null; } SnmpForXslt.setMibLoaderHolder(mibLoaderHolder); snmpConnParams.put("neighbourIPDryRun", "true"); discoveryHelper.parseDeviceRawData(rawData, discoveryTypes, snmpConnParams); SnmpForXslt.resolveIPAddresses(discoveryResource, "snmp"); snmpConnParams.put("neighbourIPDryRun", "false"); DiscoveredDeviceData discoveredDeviceData = discoveryHelper.parseDeviceRawData(rawData, discoveryTypes, snmpConnParams); Device device = discoveryHelper.createDevice(discoveredDeviceData); List<DeviceNeighbour> neighbours = device.getDeviceNeighbours(); Set<Subnet> subnets = device.getDeviceSubnets(); Set<ConnectionDetails> neighboursConnDetails = null; if (neighbours != null) { //TODO adapt for new algorthm and new DiscoveredDevice NeighbourConnectionDetails neighbourConnectionDetails = null; neighboursConnDetails = neighbourConnectionDetails.getConnectionDetailses(); } Set<ConnectionDetails> subnetConnectionDetails = null; if (subnets != null) { SubnetConnectionDetails subnetConnectionDetailsCreator = new SubnetConnectionDetails(); subnetConnectionDetailsCreator.load(subnets); neighboursConnDetails.addAll(subnetConnectionDetails); } //TODO add also own connectionDetails result = new NodeDiscoveryResult(deviceName, neighboursConnDetails, null); result.setDiscoveredData("deviceData", discoveredDeviceData); result.setDiscoveredData("rawData", rawData.getData()); return result; }
From source file:org.nuxeo.launcher.config.ConfigurationGenerator.java
/** * @param address address to check for availability * @throws ConfigurationException/*from w ww . j a va2 s . co m*/ * @since 5.5 */ public static void checkAddressReachable(InetAddress address) throws ConfigurationException { try { log.debug("Checking availability of " + address); address.isReachable(ADDRESS_PING_TIMEOUT); } catch (IOException e) { throw new ConfigurationException("Unreachable bind address " + address); } }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private boolean port22Reached(String ipAddress) { boolean gotPort22Connection = false; try {//from w ww. j a v a 2s . co m InetAddress toPoll = InetAddress.getByName(ipAddress); boolean reachable = false; try { // We have to answer within a WS timeout reachable = toPoll.isReachable(5000); } catch (IOException e) { // same as unreachable, log the problem if (log.isDebugEnabled()) { log.error(e); } else { log.error(e.getMessage()); } } if (reachable) { // see if we can ssh connect to port 22 try { Socket socket = new Socket(toPoll, 22); gotPort22Connection |= socket.isConnected(); socket.close(); } catch (IOException e) { // Happens when there's no one listening // on port 22, for example. Anyway, it // means we can't connect } } } catch (UnknownHostException e) { // Ignore, it's not a valid ip! } catch (SecurityException e) { if (log.isDebugEnabled()) { log.fatal(e); } else { log.fatal(e.getMessage()); } throw e; } return gotPort22Connection; }