Guest User

Untitled

a guest
Oct 19th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package ssh;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.InetAddress;
  7. import java.util.concurrent.TimeUnit;
  8.  
  9. import net.schmizz.sshj.SSHClient;
  10. import net.schmizz.sshj.common.IOUtils;
  11. import net.schmizz.sshj.connection.channel.direct.Session;
  12. import net.schmizz.sshj.connection.channel.direct.Session.Command;
  13.  
  14. public class ssh {
  15.  
  16. static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17. static sshCredential login;
  18.  
  19. public static void main(String[] args) throws IOException {
  20. SSHClient ssh = new SSHClient();
  21. sshGUI gui = new sshGUI(ssh);
  22. gui.setupLoginUI();
  23. System.out.println("Port: " + login.port + "| IP: " + login.ip.toString() + "| Username: " + login.username + "| PasswordLength: " + login.password.length() + "| HostKey: " + login.HostKey );
  24. InetAddress ip = InetAddress.getByName("127.0.0.1");
  25. int port = 22;
  26. String username = "", password = "";
  27. String base = "";
  28. String[] tempvars;
  29. // -
  30. base = queryInput("ssh> ");
  31. tempvars = base.split("@");
  32. username = tempvars[0];
  33. tempvars = tempvars[1].split(":");
  34. ip = InetAddress.getByName(tempvars[0]);
  35. port = Integer.parseInt(tempvars[1]);
  36. password = queryInput("Password? (Leave blank for none)> ");
  37. ssh.addHostKeyVerifier("");
  38. ssh.connect(ip, port);
  39. ssh.authPassword(username, password);
  40. final Session session = ssh.startSession();
  41. try {
  42. final Command cmd = session.exec("echo test > ssh.test");
  43. System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
  44. cmd.join(5, TimeUnit.SECONDS);
  45. System.out.println("\n\n Exit stat: " + cmd.getExitStatus());
  46. } finally {
  47. session.close();
  48. }
  49. ssh.disconnect();
  50.  
  51. }
  52.  
  53. public static String queryInput(String text) {
  54. try {
  55. System.out.println(text);
  56. return br.readLine();
  57. } catch (Exception e) {
  58. System.out.println(e.getMessage() + "\n" + e.getStackTrace());
  59. return null;
  60. }
  61.  
  62.  
  63. }
  64. }
Add Comment
Please, Sign In to add comment