package com.palacesun.engine.common;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class TelnetUtil {
   public static boolean telnet(String hostname, int port, int timeout) {
      System.out.println(hostname + ":" + port);
      Socket socket = new Socket();
      boolean isConnected = false;

      try {
         socket.connect(new InetSocketAddress(hostname, port), timeout);
         isConnected = socket.isConnected();
      } catch (IOException var14) {
         System.out.println("false");
      } finally {
         try {
            socket.close();
         } catch (IOException var13) {
            System.out.println("false");
         }

      }

      return isConnected;
   }

   public static void main(String[] args) {
      Long a = System.currentTimeMillis();
      String hostname = "192.168.2.30";
      int port = 37392;
      int timeout = 100;
      boolean isConnected = telnet(hostname, port, timeout);
      System.out.println("telnet " + hostname + " " + port + "\n==>isConnected: " + isConnected);
      Long b = System.currentTimeMillis();
      System.out.println(b - a);
   }
}
