home *** CD-ROM | disk | FTP | other *** search
/ ftp.skm.com.ua / 2014.11.ftp.skm.com.ua.tar / ftp.skm.com.ua / incoming / 1100-06.pl < prev    next >
Perl Script  |  2013-11-19  |  1KB  |  58 lines

  1. #!/usr/bin/perl
  2.  
  3. use Net::Telnet;
  4.  
  5. my $login = ""; # napisat svoy
  6. my $pwd = "";   # npisat svoy
  7.  
  8.  
  9. $textred = "\033[31m";
  10. $textgreen = "\033[32m";
  11. $textreset = "\033[0m";
  12.  
  13. die "Usage: $0 <iplist.txt>\n" if( $#ARGV < 0 );
  14.  
  15. die "Error: file '$ARGV[0]' not exists\n" unless -f $ARGV[0];
  16.  
  17. close STDERR;
  18.  
  19. foreach (`cat $ARGV[0]`)
  20. {
  21.      s/[\s\r\n]//g;
  22.      $ip=$_;
  23.    @tt=`/usr/local/bin/snmpget -c knsnmppublic -v2c -OvqE  $ip 1.3.6.1.2.1.1.1.0`;
  24.    chomp(@tt[0]);
  25.    $descr=@tt[0];
  26.    if ($descr =~ /DGS-1100-06\/ME/ )  {
  27.          $descr_s="1100-06";
  28.          $hash{$ip}=$descr_s;
  29.          print "$ip - ${textgreen}alive${textreset} $descr_s \n";
  30.      } else {
  31.          print "$ip - ${textred}non${textreset} alive \n"
  32.      }
  33. }
  34.  
  35. while ( ($k,$v)= each %hash ){
  36.     print "connect to $k\n";
  37.    $ok = new Net::Telnet(Host => $k,Port => 23,Input_log  => $k.'.ilog', Option_log => $k.'.log',Timeout    => 60,Errmode => 'return');
  38.    $ok->binmode(1);
  39.    $ok->waitfor('/ogin:.*$/i');
  40.    $ok->print($login);
  41.    $ok->waitfor('/ord:.*$/i');
  42.    $ok->print($pwd);
  43.    $ok->waitfor('/#.*$/i');
  44.    sleep(1);
  45.      swcmd('enable igmp_snooping');
  46.      swcmd('config igmp_snooping vlan_name INTERNET state enable');
  47.      swcmd('config router_ports vlan_name INTERNET add 6');
  48.      swcmd('save');
  49.      #swcmd('download firmware 195.182.202.3 1100-06f_V1-00-B036_A1.hex');
  50.      print "Updates ".$ip." sucesfull ".localtime().".\n";
  51.      $res = $ok->cmd('logout');
  52. }
  53.  
  54. sub swcmd($) {
  55.     local $cmd = shift;
  56.     $res = $ok->cmd($cmd);
  57. }
  58.