예제 #1
0
        public TelnetConnection(TelnetParameters parameters)
        {
            _Client = new TcpClient(parameters.Host, parameters.Port);
            _Client.ReceiveTimeout = 10000;

            ReadTextUntilEventAndHandleTelnetCommands(s => s.EndsWith("login:"******"\r\n");
            ReadTextUntilEventAndHandleTelnetCommands(s => s.EndsWith("password:"******"\r\n");

            string marker = "----com.sysprogs.telnet.start----";

            WriteText($"echo {marker}\n");
            string text = ReadTextUntilEventAndHandleTelnetCommands(s => s.EndsWith(marker) || s.EndsWith("Login incorrect"));

            if (text.Contains("echo " + marker))
            {
                //This is the command echo. Wait for the actual command output.
                text = ReadTextUntilEventAndHandleTelnetCommands(s => s.EndsWith(marker) || s.EndsWith("Login incorrect"));
            }
            if (!text.Contains(marker))
            {
                throw new Exception("Failed to login");
            }

            _Client.ReceiveTimeout = 0;
        }
 public TelnetTarget(TelnetParameters telnetParams)
 {
     _Parameters = telnetParams;
     _ConnectionPool.Push(new TelnetConnection(_Parameters));
 }