-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExecTest.cs
43 lines (34 loc) · 906 Bytes
/
ExecTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using Tamir.SharpSsh.jsch;
using System.Collections;
using System.IO;
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for ExecTest.
/// </summary>
public class ExecTest
{
public static void Run()
{
JSch jsch=new JSch();
Session session=jsch.getSession("root", "rhmanage", 22);
session.setPassword( "cisco" );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("ifconfig");
StreamReader sr = new StreamReader( channel.getInputStream() );
channel.connect();
string line;
while( (line=sr.ReadLine()) != null )
{
Console.WriteLine( line );
}
channel.disconnect();
session.disconnect();
}
}
}