Chinaunix首页 | 论坛 | 博客
  • 博客访问: 541902
  • 博文数量: 201
  • 博客积分: 7734
  • 博客等级: 少将
  • 技术积分: 1994
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-09 19:18
文章分类

全部博文(201)

文章存档

2011年(28)

2010年(173)

分类: Python/Ruby

2011-04-14 10:29:29

start:
[root@linkinfor ~]# cat /tmp/telnet/ip.txt
192.168.254.131
192.168.254.131
[root@linkinfor ~]# cat /tmp/telnet/command.txt
show users
show login
  1. #!/usr/bin/perl -w
  2. use Net::Telnet::Cisco;

  3. open INPUT,"/tmp/telnet/ip.txt";

  4. while ($ip=<INPUT>)
  5. { #1#
  6.   chomp ($ip);
  7.   my $telnet = Net::Telnet::Cisco->new(Host => $ip);
  8.   $telnet->login('admin', '123');
  9.   open L,"/tmp/telnet/command.txt";

  10.      while ($command=<L>)
  11.     { ##2##
  12.       print $command;
  13.       chomp ($command);
  14.       my @output = $telnet->cmd($command);
  15.      
  16.      open (OUT, ">>/tmp/log$ip.txt");
  17.        for my $i (@output) { ###3###
  18.          print "$i\n";
  19.          print OUT $i;
  20.       } ###3###
  21.      close (OUT);
  22.     } ##2##
  23.       $telnet->close;
  24. } #1#

result:

[root@linkinfor ~]# cat /tmp/log192.168.254.131.txt
    Line       User       Host(s)              Idle       Location
   0 con 0                idle                 01:16:52  
*194 vty 0     admin      idle                 00:00:00 192.168.0.20

  Interface    User               Mode         Idle     Peer Address

     No login delay has been applied.
     No Quiet-Mode access list has been configured.

     Router NOT enabled to watch for login Attacks

    Line       User       Host(s)              Idle       Location
   0 con 0                idle                 01:16:53  
*195 vty 1     admin      idle                 00:00:00 192.168.0.20

  Interface    User               Mode         Idle     Peer Address

     No login delay has been applied.
     No Quiet-Mode access list has been configured.

     Router NOT enabled to watch for login Attacks

[root@linkinfor ~]# cat /tmp/log192.168.254.131.txt
    Line       User       Host(s)              Idle       Location
   0 con 0                idle                 01:16:52  
*194 vty 0     admin      idle                 00:00:00 192.168.0.20

  Interface    User               Mode         Idle     Peer Address

     No login delay has been applied.
     No Quiet-Mode access list has been configured.

     Router NOT enabled to watch for login Attacks

    Line       User       Host(s)              Idle       Location
   0 con 0                idle                 01:16:53  
*195 vty 1     admin      idle                 00:00:00 192.168.0.20

  Interface    User               Mode         Idle     Peer Address

     No login delay has been applied.
     No Quiet-Mode access list has been configured.

     Router NOT enabled to watch for login Attacks

PS、

 

  1. open (OUT, ">>/tmp/log$ip.txt");
  2.        foreach (@output) { ###3###
  3.          print "$_\n";
  4.          print OUT $_;
  5.       } ###3###
  6.      close (OUT);
  1. open INPUT,";
  2. while ($ip=<INPUT>)
  3. {
  4.   chomp ($ip);
  5.   my $telnet = Net::Telnet::Cisco->new(Host => $ip);
  6.   $telnet->login('a', 'a');
  7.   open L,"/tmp/telnet/command.txt";
  8.      while ($command=<L>)
  9.     {
  10.       chomp ($command);
  11.     open (SLIP, ">>/tmp/log$ip.txt");
  12.     my $MI = "\n=============================$command======================\n";
  13.     print SLIP $MI;
  14.       my @output = $telnet->cmd($command);
  15.     open (OUT, ">>/tmp/log$ip.txt");
  16.     for my $i (@output)
  17.         {
  18.             print "$i\n";
  19.             print OUT $i;
  20.          }
  21.     }
阅读(1261) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

vito_huang2011-09-09 14:45:35

为什么没有内容?