Refine search
public void checkHosts(String subnet){ int timeout=1000; for (int i=1;i<255;i++){ String host=subnet + "." + i; if (InetAddress.getByName(host).isReachable(timeout)){ System.out.println(host + " is reachable"); } } }
import java.io.IOException; import java.net.InetAddress; public class IsReachable { public static void main(final String[] args) throws IOException { final InetAddress host = InetAddress.getByName(args[0]); System.out.println("host.isReachable(1000) = " + host.isReachable(1000)); } }
success = InetAddress.getByName(host).isReachable(timeout); } else { SocketAddress socketAddress = new InetSocketAddress(host, port);
private ArrayList<String> scanSubNet(String subnet){ ArrayList<String> hosts = new ArrayList<String>(); InetAddress inetAddress = null; for(int i=1; i<10; i++){ Log.d(TAG, "Trying: " + subnet + String.valueOf(i)); try { inetAddress = InetAddress.getByName(subnet + String.valueOf(i)); if(inetAddress.isReachable(1000)){ hosts.add(inetAddress.getHostName()); Log.d(TAG, inetAddress.getHostName()); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return hosts; }
private boolean systemPing( String hostname, int timeout ) { boolean retval = false; InetAddress address = null; try { address = InetAddress.getByName( hostname ); if ( address == null ) { logError( BaseMessages.getString( PKG, "JobPing.CanNotGetAddress", hostname ) ); return retval; } if ( log.isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobPing.HostName", address.getHostName() ) ); logDetailed( BaseMessages.getString( PKG, "JobPing.HostAddress", address.getHostAddress() ) ); } retval = address.isReachable( timeout ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "JobPing.ErrorSystemPing", hostname, e.getMessage() ) ); } return retval; }
private static boolean isHostReachable(final String host) { try { return InetAddress.getByName(host).isReachable(1000); } catch (IOException ignored) { } return false; }
if (InetAddress.getByName("www.xy.com").isReachable(timeout)) { } else { }
String host = "172.16.0.2"; int timeOut = 3000; long[] time = new long[5]; Boolean reachable; for(int i = 0; i < 5; i++) { long BeforeTime = System.currentTimeMillis(); reachable = InetAddress.getByName(host).isReachable(timeOut); long AfterTime = System.currentTimeMillis(); Long TimeDifference = AfterTime - BeforeTime; time[i] = TimeDifference; }
public void checkOnlineState() { ConnectivityManager CManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo NInfo = CManager.getActiveNetworkInfo(); if (NInfo != null && NInfo.isConnectedOrConnecting()) { if (InetAddress.getByName("www.xy.com").isReachable(timeout)) { // host reachable } else { // host not reachable } } return; }
@Override public boolean initializeAdapter(Map<String, Object> config) { try { if (!InetAddress.getByName(host).isReachable(500)) { throw new Exception("Unable to reach host " + host); } Class.forName(this.config.getClassName()); connection = DriverManager.getConnection(this.config.getJdbcUrl()); connection.setReadOnly(true); if (!connection.isValid(0)) { throw new Exception("Invalid connection string...."); } statement = connection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); return true; } catch (Exception e) { _LOG.error("[Metron] JDBC connection failed....", e); return false; } }
InetAddress address = InetAddress.getByName(targetHost); return address.isReachable(pingMeta.getPingTimeoutMillis()); }else{ String cmd = "";
try { InetAddress.getByName("your server url").isReachable(2000); //Replace with your name return true; } catch (Exception e) { return false; }
public static boolean isOnline() { try { InetAddress.getByName("google.com").isReachable(3); return true; } catch (UnknownHostException e){ return false; } catch (IOException e){ return false; } }
public boolean isServerReachable() // To check if server is reachable { try { InetAddress.getByName("google.com").isReachable(3000); //Replace with your name return true; } catch (Exception e) { return false; } }
public boolean isServerAlive() // To check if server is reachable { try { InetAddress.getByName("google.com").isReachable(3000); //Replace with your name return true; } catch (Exception e) { return false; } }
public boolean getIcmpStatus() throws IOException { InetAddress inetAddress=InetAddress.getByName(ipAddressStr); boolean reachable = inetAddress.isReachable(timeout); return reachable; }
public boolean getIcmpStatus(String ipAddressStr) throws IOException { InetAddress inetAddress=InetAddress.getByName(ipAddressStr); boolean reachable = inetAddress.isReachable(timeout); return reachable; }
public static boolean getIcmpStatus(String ipAddressStr,int timeout) throws IOException { InetAddress inetAddress=InetAddress.getByName(ipAddressStr); boolean reachable = inetAddress.isReachable(timeout); return reachable; }
if (InetAddress.getByName("www.google.com").isReachable(2000)){ // 2000 = timeout // connection is available. google is a good candidate } else { // no connection }
public boolean isServerReachable() // To check if server is reachable { try { InetAddress.getByName("google.com").isReachable(3000); //Replace with your name return true; } catch (Exception e) { return false; } }