-
-
Notifications
You must be signed in to change notification settings - Fork 947
Running RunCommand in the SshClient class on an cisco asa results in hanging forever #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On what line would it actually block? |
Hello. I have already downloaded the source and can do some simple troubleshooting tommorow. I will look into it i maybe have ASA we can test on. |
Have fixed an asa you can test on. Should i send the login information to the email on your profile? |
Yes, that's ok. I'm not sure I'll have time today, but I'll look into it asap. |
I've exactly the same problem when I try acces to Mitrastar FTTH router. |
The problem with the ASA was that it does not properly support the "exec" channel request message.
I've supplied @ravelund with a solution offline, which uses our ShellStream - with its Expect capabilities - instead. |
@drieseng seems to be correct. Found this via google: Sounds like you have to work with Shell + Expect. |
Also with @drieseng input i have created this function:
By suppling the commands string array with The terminal pager 0 command on the asa skips the more question. And this works. The only - here is that you have to wait for the command to timeout. |
I actually sent you a basic implemention that uses ShellStream and Except. |
Would you mind posting the workaround solution, @drieseng ? I'm encountering what looks like the same issue, but working from a prebuilt dll that I don't have the luxury of picking apart in the debugger. I'm going to try @ravelund 's solution for now, but if there's a more correct/compact implementation, that would be useful. |
Hello i did it something like this.
Not the most sexy code but it worked for my needs.
/// <summary>
/// Sets the command timeout for Ssh and (Default 40 seconds)
/// </summary>
public TimeSpan CommandTimeOut { get; set; } = new TimeSpan(0,0,0,40);
using (var client = new SshClient(host, port, username, password))
{
try
{
client.Connect();
string command = "sh run";
SshCommand runcommand = client.CreateCommand(command);
runcommand.CommandTimeout = CommandTimeOut;
runcommand.Execute();
string resultString = returnString = runcommand.Result;
}
catch (SshOperationTimeoutException)
{
Console.WriteLine($"ExecuteCommandSsh: Command timeout
{CommandTimeOut} seconds");
}
}
Regards
Ravleund
…On 26 May 2017 at 17:34, NNskelly ***@***.***> wrote:
Would you mind posting the workaround solution, @drieseng
<https://github.com/drieseng> ? I'm encountering what looks like the same
issue, but working from a prebuilt dll that I don't have the luxury of
picking apart in the debugger. I'm going to try @ravelund
<https://github.com/ravelund> 's solution for now, but if there's a more
correct/compact implementation, that would be useful.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#52 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ATuXwVWONTgEKLDO9Ur5FsJzFHX3DiKLks5r9vEcgaJpZM4JWI9s>
.
|
This was another way of doing it:
using System;
using System.Text.RegularExpressions;
using Renci.SshNet;
class SshTest
{
public static void Main()
{
using (var client = new SshClient("myhost", 22, "admin",
"adminpassword"))
{
client.Connect();
var shellStream = client.CreateShellStream("xterm", 80, 600, 0,
0, 32 * 1024);
// wait for the shell prompt to appear, and when it does
execute the 'sh version' command
shellStream.Expect(CreateShellPromptExecuteCommandExpectAction(shellStream,
"sh version"));
while (client.IsConnected)
{
// while we're connected we either:
// * expect a 'more' prompt, and send a single whitespace
to have the next page appear
// * expect a shell prompt, which signals that the command
has finished and as such we disconnect the client
shellStream.Expect(CreateMoreExpectAction(shellStream),
CreateShellPromptDisconnectClientExpectAction(client));
}
}
}
private static ExpectAction CreateMoreExpectAction(ShellStream
shellStream)
{
return new ExpectAction(new Regex(@".*<---\sMore\s--->$"), (text) =>
{
Console.WriteLine(text);
shellStream.Write(" ");
});
}
private static ExpectAction
CreateShellPromptDisconnectClientExpectAction(SshClient client)
{
return new ExpectAction(new Regex(".*sshdebugasa\\>\\s$"), (text) =>
{
Console.WriteLine(text);
client.Disconnect();
});
}
private static ExpectAction
CreateShellPromptExecuteCommandExpectAction(ShellStream shellStream, string
command)
{
return new ExpectAction(new Regex(".*sshdebugasa\\>\\s$"), (text) =>
{
Console.WriteLine(text);
shellStream.WriteLine(command);
});
}
}
…On 28 May 2017 at 14:03, Ole Morten Aaslund ***@***.***> wrote:
Hello i did it something like this.
Not the most sexy code but it worked for my needs.
/// <summary>
/// Sets the command timeout for Ssh and (Default 40 seconds)
/// </summary>
public TimeSpan CommandTimeOut { get; set; } = new TimeSpan(0,0,0,40);
using (var client = new SshClient(host, port, username, password))
{
try
{
client.Connect();
string command = "sh run";
SshCommand runcommand = client.CreateCommand(command);
runcommand.CommandTimeout = CommandTimeOut;
runcommand.Execute();
string resultString = returnString = runcommand.Result;
}
catch (SshOperationTimeoutException)
{
Console.WriteLine($"ExecuteCommandSsh: Command timeout
{CommandTimeOut} seconds");
}
}
Regards
Ravleund
On 26 May 2017 at 17:34, NNskelly ***@***.***> wrote:
> Would you mind posting the workaround solution, @drieseng
> <https://github.com/drieseng> ? I'm encountering what looks like the
> same issue, but working from a prebuilt dll that I don't have the luxury of
> picking apart in the debugger. I'm going to try @ravelund
> <https://github.com/ravelund> 's solution for now, but if there's a more
> correct/compact implementation, that would be useful.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#52 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/ATuXwVWONTgEKLDO9Ur5FsJzFHX3DiKLks5r9vEcgaJpZM4JWI9s>
> .
>
|
Thanks! Trying an explicitly constructed command with a timeout as per the first example still jammed up for me for the duration of the timeout, and returned without apparently having executed anything. It's nice to have the Expect solution on record as an alternative. |
@ravelund the second solution worked for me, Thank a lot!! |
Running the bellow code on a Cisco ASA result in an forever hang.
using (var client = new SshClient(host, 22, username, password))
{
client.Connect();
var result = client.RunCommand(command);
returnString = result.Result;
client.Disconnect();
}
The text was updated successfully, but these errors were encountered: