Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- no warnings;
- use Net::SSH::Perl;
- use IO::Socket::INET;
- use threads;
- use threads::shared;
- #cmd to exec
- my $cmd = 'uname';
- #threads num
- my $thrnm = 1;
- #Connection timeout (sec)
- my $timeout = 5;
- #ip's
- my $ifile = './cred.txt';
- #exec result list
- my $rfile = './res.txt';
- my @ilist : shared = loadf($ifile);
- $| = 1;
- my @trl = ();
- $trl[$_] = threads->create(\&main) for 0..$thrnm - 1;
- $_->join for @trl;
- sub main
- {
- while(@ilist)
- {
- my ($host, $user, $pass) = split /:/, shift @ilist;
- my $sock = IO::Socket::INET->new(PeerAddr => $host, PeerProto => 'tcp', PeerPort => 22, Timeout => $timeout);
- unless($sock)
- {
- print "No connection to $host:22\n";
- next;
- }
- my ($one, $two, undef) = ssh_it($host, $user, $pass, $cmd);
- if($one)
- {
- writef($rfile, "OK - $host:$user:$pass:$one\n");
- }
- elsif($two)
- {
- writef($rfile, "Err - $host:$user:$pass:$two\n");
- }
- }
- }
- sub ssh_it
- {
- my ($host, $user, $pass, $cmd) = @_;
- my $ssh = Net::SSH::Perl->new($host);
- #...
- eval
- {
- $ssh->login($user, $pass);
- };
- unless($@)
- {
- print "[+] $host:$user:$pass\n";
- my ($stdout, $stderr, undef) = $ssh->cmd($cmd);
- return ($stdout, $stderr);
- }
- else
- {
- print "[-] $host:$user:$pass\n";
- }
- return 0;
- }
- sub writef
- {
- open(F, '>>', $_[0]) || warn $_[0].' - '.$!."\n";
- print F $_[1];
- close F;
- }
- sub loadf
- {
- open(F, '<', $_[0]) || die $_[0].' - '.$!."\n";
- chomp(my @list = <F>);
- close F;
- return @list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement