purge_bdcom.pm 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use Modern::Perl;
  2. use utf8;
  3. use telnet;
  4. async purge_bdcom => sub
  5. {
  6. my $ip = shift;
  7. my $login = shift;
  8. my $password = shift;
  9. my $tree = shift;
  10. ############################
  11. my $t = new telnet($ip);
  12. # $t->debug(1);
  13. await $t->connect;
  14. await $t->reply(qr/Username:/, $login);
  15. await $t->reply(qr/Password:/, $password);
  16. my @greeting = await $t->waitfor(qr/>/);
  17. my $version = "C";
  18. for (@greeting)
  19. {
  20. $version = $1 if /Welcome to BDCOM P3310(\w)/;
  21. }
  22. $t->print("enable");
  23. my @next = await $t->waitfor(qr/#|password:/);
  24. if (grep {$_ =~ /password:/} @next)
  25. {
  26. $t->print($password);
  27. await $t->waitfor(qr/#/);
  28. }
  29. $t->prompt(qr/#/);
  30. await $t->cmd("terminal length 0");
  31. await $t->cmd("terminal width 200");
  32. #######################
  33. my @lines = await $t->cmd("show epon active-onu interface ePON 0/$tree");
  34. $lines[0] =~ m|Interface EPON0/\d+ has bound (\d+) active ONUs|;
  35. my $count = $1 || "?";
  36. $t->close;
  37. return $count;
  38. };
  39. 1;