Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: su command

$
0
0
hi vaccaridaniele,

why do you use this regular expressions? Look at my code at the end of this posting. It is just an adapted copy of yours. ;) But it runs endless the while loop.
            var connectionInfo = new ConnectionInfo("server", 22, "user",
                new PrivateKeyAuthenticationMethod("user",
                     new PrivateKeyFile(File.OpenRead(@"C:\Path\to\file\file.key"), "")));

            using (var client = new Renci.SshNet.SshClient(connectionInfo))
          {
              try
              {
                  client.Connect();
                  ShellStream shells = client.CreateShellStream("test", 80, 24, 800, 600, 1024);
                  Regex regex = new Regex(@"\[.*@.*\][\$|\#]");

                  shells.WriteLine("su");
                  String outp = "";
                  var match = regex.Match(outp);

                  while ((shells.DataAvailable || !match.Success || outp == ""))
                  {

                      outp += shells.Read();
                      Console.WriteLine(outp);
                      match = regex.Match(outp); 
                      Console.WriteLine(shells.DataAvailable);
                      Console.WriteLine(match.Success);
                  }
                 shells.WriteLine("password");
                  outp = "";
                  match = regex.Match(outp);
                  while (shells.DataAvailable || !match.Success || outp == "")
                  {
                      outp += shells.Read();
                      Console.WriteLine(outp);
                      match = regex.Match(outp);
                  }
                  client.Disconnect();
              }
              catch (SshAuthenticationException ex)
              {
                  Console.WriteLine(ex.Message);
              }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>