$s = "nnn MAC address learned in routing instance PPPoE-xxx bridge domain __PPPoE-xxxx__";
if ($s =~ /(\d)(?=\s)/) # Найти цифру за которой стоит '\s'(пробел)
{
print "$1\n";
}
else { print "ошибка поиска\n";}
#!/usr/bin/perl
use strict;
use warnings;
open(my $file, 'log.txt') or die "Could not open file $!";
my $first = <$file>;
if ($first =~ /^(\d+)(?=\s)/)
{
print "$1\n";
}
else { print "ошибка поиска\n";}
$s = "nnn MAC address learned in routing instance PPPoE-xxx bridge domain __PPPoE-xxxx__";
if ($s =~ /^(\d)(?=\s)/) # Найти цифру за которой стоит '\s'(пробел)
{
print "$1\n";
}
else { print "ошибка поиска\n";}
#!/usr/local/bin/perl
use Time::HiRes;
use Net::Telnet;
use strict;
use warnings;
$user = "admin";
$pass = "1234";
open (IPLIST, "iplist.txt");
open (WRFILE, ">>log.txt");
while ($host = <IPLIST>)
{
$th = new Net::Telnet(Timeout => 15, Telnetmode => 1,Errmode => "return");
print "======================= START =======================\n";
print "[+] Connectiong to: ".$host."\n";
print "=====================================================\n";
print WRFILE "======================= START =======================\n";
print WRFILE "[+] Connectiong to: ".$host."\n";
print WRFILE "=====================================================\n";
$th->open($host);
$th->waitfor('/ser name:.*$/');
$th->print($user);
$th->waitfor('/assword:.*$/');
$th->print($pass);
$th->waitfor('/#.*$/');
open (COMMANDS, "commands");
while ($cmds = <COMMANDS>)
{
$th->print($cmds);
@out = $th->waitfor('/#.*$/');
print @out;
print WRFILE @out;
}
close(COMMANDS);
open(my $file, 'log.txt') or die "Could not open file $!";
my $first = <$file>;
if ($first =~ /^(\d+)(?=\s)/)
{
print "$1\n";
}
else { print "ошибка поиска\n";}
close(my $file, 'log.txt');
print "\n=================== END ===================\n\n\n";
print WRFILE "\n=================== END ===================\n\n\n";
Time::HiRes::sleep(10);
}
close(WRFILE);
close(IPLIST);
#!/usr/bin/perl
use Net::Telnet;
use strict;
use warnings;
my $user = "admin";
my $pass = "12345";
open(my $iplist, "iplist.txt");
open(my $log, ">>log.txt");
open(my $counts, ">>counts.txt");
open(my $cmds, "commands");
my @commands = <$cmds>;
while (my $host = <$iplist>)
{
chomp($host);
my $th = new Net::Telnet(Timeout => 15, Telnetmode => 1,Errmode => "return");
print "\n======================= START =======================\n";
print "[+] Connecting to: ".$host."\n";
print "=====================================================\n";
print $log "\n======================= START =======================\n";
print $log "[+] Connecting to: ".$host."\n";
print $log "=====================================================\n";
$th->open($host);
$th->waitfor('/login|user name/i');
$th->print($user);
$th->waitfor('/password/i');
$th->print($pass);
my $i = 1;
foreach my $cmd (@commands)
{
$th->waitfor('/[$#]/');
my @out = $th->cmd($cmd);
print @out;
print $log @out;
foreach my $line (@out)
{
if ($line =~ /^(\d+)(?= MAC address learned)/)
{
print $counts $host.": ".$i.",".$1."\n";
$i++;
}
}
}
}
close($iplist);
close($log);
close($counts);
close($cmds);
#!/usr/bin/perl
use warnings;
use strict;
use Net::SSH2;
use IO::File;
my $host = '77.39.84.16';
my ($user) = 'av_bondarchuk';
my ($password) = '314MyP753';
open my $log, '>>', "log.txt" or die "can't open logfile: $! ";
open my $counts, '>>', "counts.txt" or die "can't open counts: $! ";
my $cmds = 'show vpls mac-table count instance PPPoE-STV-ATS24';
my @commands = $cmds;
my $ssh2 = Net::SSH2->new();
$ssh2->connect($host) or die "Can not connect to $host $@ \n";
$ssh2->auth_password($user, $password) or die "Can not login with $user/$password\n";
my $i = 1;
foreach my $cmd (@commands)
{
my @out = $ssh2->cmd($cmd);
print @out;
print $log @out;
foreach my $line (@out)
{
if ($line =~ /^(\d+)(?= MAC address learned)/)
{
print $counts $host.": ".$i.",".$1."\n";
$i++;
}
}
}
print 'done';
close($log);
close($counts);
close($cmds);