blob: d6a661fc7fa20f97ac443645b8b989473536bec9 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.preferences.ui.utils;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class CheckStateServerName {
public static String doCheckState(String servername, int timeoutMilliSecs) {
try {
InetAddress address = InetAddress.getByName(servername);
// System.out.println("Name: " + address.getHostName());
// System.out.println("Addr: " + address.getHostAddress());
// System.out.println("Reach: " + address.isReachable(3000));
if (!address.isReachable(timeoutMilliSecs)) {
return servername+" not reachable in "+timeoutMilliSecs+" milliseconds";
}
return null;
}
catch (UnknownHostException e) {
return "Unable to lookup "+servername;
}
catch (IOException e) {
return "Unable to reach "+servername;
}
}
}