Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. sub connectSSH{
  2. my $user = "...";
  3. my $password = "...";
  4.  
  5. my $ssh2 = Net::SSH2->new();
  6. my $chan;
  7. if($ssh2->connect($ip,$port,Timeout => 10)){
  8. if(!$ssh2->auth_password($user, $password)){
  9. print"Error: Password wrongn";
  10. exit;
  11. }else{
  12. $chan = $ssh2->channel(); # SSH
  13. $chan->blocking(0);
  14. $chan->shell();
  15. }
  16. }else{
  17. print "Connection to $ip not possiblen";
  18. exit;
  19. }
  20. return $chan;
  21. }
  22.  
  23. sub sendCommand{
  24. my ($chan,$command) = @_;
  25. my @output=();
  26.  
  27. print $chan "$commandn";
  28. #usleep(500)
  29. push(@output,"$_") while <$chan>;
  30.  
  31. #process output...
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement