import java.net.InetSocketAddress;
import java.net.Socket;
 
public class CheckConnection {
   public static void main(String[] args) {
      if (args.length != 2) {
         System.err.println("Usage: java CheckConnection <host> <port>");
         System.exit(1);
      }
 
      try {
         String address = args[0];
         int port = Integer.parseInt(args[1]);
 
         Socket socket = new Socket();
         socket.connect(new InetSocketAddress(address, port), 5000);
         socket.close();
 
         System.out.println(args[0] + ":" + args[1] + " - OK");
         System.exit(0);
      } catch (Exception e) {
         System.err.println(args[0] + ":" + args[1] + " - KO");
         System.exit(1);
      }
   }
}
 
Powered by GeSHi