-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJschTest.java
More file actions
37 lines (33 loc) · 1.29 KB
/
JschTest.java
File metadata and controls
37 lines (33 loc) · 1.29 KB
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
package com.xmuchen.jschtest;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
public class JschTest {
public static void main(String args[]) throws JSchException, UnsupportedEncodingException {
JSch jsch = new JSch();
String host = null;
String user = null;
String password = null;
user = "root";
host = "192.168.100.1";//"ec2-54-242-46-232.compute-1.amazonaws.com";
password = "netgear";
//jsch.addIdentity("/home/lbchen/aws/keypair/lbcone.pem");
Session session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel = session.openChannel("exec");
String input = null;
input = "dpctl show tcp:127.0.0.1";
InputStream insts = new ByteArrayInputStream(input.getBytes("UTF-8"));
((ChannelExec)channel).setCommand(input);
// channel.setInputStream(insts);
channel.setOutputStream(System.out);
channel.connect(3000);
}
}