Examples of TelnetClient


Examples of com.davfx.ninio.telnet.TelnetClient

     
      @Override
      public void connect(WaitingTelnetClientHandler clientHandler) {
        Hold c = clients.get(address);
        if (c == null) {
          TelnetClient telnetClient = new TelnetClient();
          if (!Double.isNaN(callWithEmptyTime)) {
            telnetClient.withCallWithEmptyTime(callWithEmptyTime);
          }
          if (readyFactory != null) {
            telnetClient.override(readyFactory);
          }
         
          WaitingTelnetClient waitingTelnetClient = new WaitingTelnetClient(telnetClient.withAddress(address).withQueue(queue, callWithEmptyExecutor));
          if (!Double.isNaN(endOfCommandTime)) {
            waitingTelnetClient.withEndOfCommandTime(endOfCommandTime);
          }
          if (!Double.isNaN(timeout)) {
            waitingTelnetClient.withTimeout(timeout);
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

            System.err.println(
                "Exception while opening the spy file: "
                + e.getMessage());
        }

        tc = new TelnetClient();

        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

        final String obfuscatedCmd = cmd.toCommandLine(os, true);
        logger.info("Starting command [{}] on [{}]", obfuscatedCmd, this);

        try {
            final TelnetClient tc = new TelnetClient();
            tc.setConnectTimeout(connectionTimeoutMillis);
            tc.addOptionHandler(new WindowSizeOptionHandler(299, 25, true, false, true, false));
            logger.info("Connecting to telnet://{}@{}", username, address);
            tc.connect(address, port);
            final InputStream stdout = tc.getInputStream();
            final OutputStream stdin = tc.getOutputStream();
            final PipedInputStream callersStdout = new PipedInputStream();
            final PipedOutputStream toCallersStdout = new PipedOutputStream(callersStdout);
            final ByteArrayOutputStream outputBuf = new ByteArrayOutputStream();
            final int[] exitValue = new int[1];
            exitValue[0] = -1;

            final Thread outputReaderThread = new Thread("Telnet output reader") {
                @Override
                public void run() {
                    try {
                        receive(stdout, outputBuf, toCallersStdout, "ogin:");
                        send(stdin, username);

                        receive(stdout, outputBuf, toCallersStdout, "assword:");
                        send(stdin, password);

                        receive(stdout, outputBuf, toCallersStdout, ">", "ogon failure");
                        send(stdin, "PROMPT " + DETECTABLE_WINDOWS_PROMPT);
                        // We must wait for the prompt twice; the first time is an echo of the PROMPT command,
                        // the second is the actual prompt
                        receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                        receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                        if (workingDirectory != null) {
                            send(stdin, "CD /D " + workingDirectory.getPath());
                            receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                        }

                        send(stdin, cmd.toCommandLine(getHostOperatingSystem(), false));

                        receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                        send(stdin, "ECHO \"" + ERRORLEVEL_PREAMBLE + "%errorlevel%" + ERRORLEVEL_POSTAMBLE);
                        receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                        receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                        String outputBufStr = outputBuf.toString();
                        int preamblePos = outputBufStr.indexOf(ERRORLEVEL_PREAMBLE);
                        int postamblePos = outputBufStr.indexOf(ERRORLEVEL_POSTAMBLE);
                        if (preamblePos >= 0 && postamblePos >= 0) {
                            String errorlevelString = outputBufStr.substring(preamblePos + ERRORLEVEL_PREAMBLE.length(), postamblePos);
                            logger.debug("Errorlevel string found: {}", errorlevelString);

                            try {
                                synchronized (exitValue) {
                                    exitValue[0] = Integer.parseInt(errorlevelString);
                                }
                            } catch (NumberFormatException exc) {
                                logger.error("Cannot parse errorlevel in Windows output: " + outputBuf);
                            }
                        } else {
                            logger.error("Cannot find errorlevel in Windows output: " + outputBuf);
                        }
                    } catch (IOException exc) {
                        throw new RuntimeIOException(format("Cannot start command [%s] on [%s]", obfuscatedCmd, CifsTelnetConnection.this), exc);
                    } finally {
                        closeQuietly(toCallersStdout);
                    }
                }
            };
            outputReaderThread.setDaemon(true);
            outputReaderThread.start();

            return new OverthereProcess() {
                @Override
                public synchronized OutputStream getStdin() {
                    return stdin;
                }

                @Override
                public synchronized InputStream getStdout() {
                    return callersStdout;
                }

                @Override
                public synchronized InputStream getStderr() {
                    return new ByteArrayInputStream(new byte[0]);
                }

                @Override
                public synchronized int waitFor() {
                    if (!tc.isConnected()) {
                        return exitValue[0];
                    }

                    try {
                        try {
                            outputReaderThread.join();
                        } finally {
                            disconnect();
                        }
                        return exitValue[0];
                    } catch (InterruptedException exc) {
                        throw new RuntimeIOException(format("Cannot start command [%s] on [%s]", obfuscatedCmd, CifsTelnetConnection.this), exc);
                    }
                }

                @Override
                public synchronized void destroy() {
                    if (!tc.isConnected()) {
                        return;
                    }

                    disconnect();
                }

                private synchronized void disconnect() {
                    try {
                        tc.disconnect();
                        logger.info("Disconnected from {}", CifsTelnetConnection.this);

                        closeQuietly(toCallersStdout);
                    } catch (IOException exc) {
                        throw new RuntimeIOException(format("Cannot disconnect from %s", CifsTelnetConnection.this), exc);
                    }
                }

                @Override
                public synchronized int exitValue() {
                    if (tc.isConnected()) {
                        throw new IllegalThreadStateException(format("Process for command [%s] on %s is still running", obfuscatedCmd, CifsTelnetConnection.this));
                    }

                    synchronized (exitValue) {
                        return exitValue[0];
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

  @Override
  public Boolean eventDetect() {
    logger.debug("Iniciando deteccion de servicios");
    Boolean detected = Boolean.FALSE;
   
    TelnetClient telnet = new TelnetClient();
   
    try {
      telnet.connect(getEvent().getHost(), new Integer(getEvent().getPort()));
    } catch (Exception e) {
      // Se detecta el servicio caido
      logger.debug("Se detecta la caida del servicio: " + getEvent().getHost() + ":" + getEvent().getPort());
      detected = Boolean.TRUE;
    }
   
    if (telnet.isConnected()){
      try {
        telnet.disconnect();
      } catch (IOException e) {
        logger.error(Tools.getStackTrace(e));
      }
    }
    logger.debug("Fin deteccion de servicios");
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

  protected void connectPort() throws GatewayException, IOException, InterruptedException
  {
    try
    {
      Logger.getInstance().logInfo("Opening: " + this.ipAddress + " @" + this.ipPort, null, getGateway().getGatewayId());
      this.tc = new TelnetClient();
      this.tc.addOptionHandler(this.ttopt);
      this.tc.addOptionHandler(this.echoopt);
      this.tc.addOptionHandler(this.gaopt);
      if (getGateway().getIpProtocol() == IPProtocols.BINARY) this.tc.addOptionHandler(this.binaryopt); // Make telnet session binary, so ^Z in ATHander.Sendmessage is send raw!
      if (getGateway().getIpEncryption())
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

            System.err.println(
                "Exception while opening the spy file: "
                + e.getMessage());
        }

        tc = new TelnetClient();

        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

public final class weatherTelnet
{

    public final static void main(String[] args)
    {
        TelnetClient telnet;

        telnet = new TelnetClient();

        try
        {
            telnet.connect("rainmaker.wunderground.com", 3000);
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
        }

        IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
                         System.in, System.out);

        try
        {
            telnet.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

    return optionHandlers;
  }
 
  public void start() {

    tc = new TelnetClient();
   
    Hashtable optionHandlers = getOptionHandler(getServerType());

    TerminalTypeOptionHandler ttopt = (TerminalTypeOptionHandler) optionHandlers.get("ttopt");
    EchoOptionHandler echoopt = (EchoOptionHandler) optionHandlers.get("echoopt");
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

    m_writer.println(command);
    m_writer.flush();
  }

  protected void connect() throws IOException {
    m_telnetClient = new TelnetClient();
    m_telnetClient.connect(m_host, m_remoteManagerListenerPort);

    m_reader = new BufferedReader(new InputStreamReader(
        new BufferedInputStream(m_telnetClient.getInputStream(), 1024),
        "ASCII"));
View Full Code Here

Examples of org.apache.commons.net.telnet.TelnetClient

            System.err.println(
                "Exception while opening the spy file: "
                + e.getMessage());
        }

        tc = new TelnetClient();

        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.