Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Properties;
  5.  
  6. import com.jcraft.jsch.Channel;
  7. import com.jcraft.jsch.ChannelExec;
  8. import com.jcraft.jsch.JSch;
  9. import com.jcraft.jsch.JSchException;
  10. import com.jcraft.jsch.Session;
  11.  
  12. try {
  13. JSch js = new JSch();
  14. Session s = js.getSession("root", "164.132.47.61", 22);
  15. s.setPassword("29f3d178024866bfe34ba118473e3394964aa3fe3c4bc216599400c892dff89e");
  16. Properties config = new Properties();
  17. config.put("StrictHostKeyChecking", "no");
  18. s.setConfig(config);
  19. s.connect();
  20. Channel c = s.openChannel("exec");
  21. ChannelExec ce = (ChannelExec) c;
  22. ce.setCommand("iptables"); //aggiungi qua il comando
  23. ce.setErrStream(System.err);
  24. ce.connect();
  25. BufferedReader reader = new BufferedReader(new InputStreamReader(ce.getInputStream()));
  26. String line;
  27. while ((line = reader.readLine()) != null) {
  28. plugin.console.sendMessage(line);
  29. }
  30. ce.disconnect();
  31. s.disconnect();
  32. plugin.console.sendMessage("Exit code: " + ce.getExitStatus());
  33. } catch (IOException e) {
  34. e.printStackTrace();
  35. } catch (JSchException e) {
  36. e.printStackTrace();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement