A
A
Andrey Bondarchuk2015-02-25 14:30:57
Perl
Andrey Bondarchuk, 2015-02-25 14:30:57

What's wrong with the perl script?

Help me finish the script

use Net::Telnet;
use IO::File;

open my ($ip) = (IPlist, "iplist" or die "can't open iplist: $!");

my ($username) = 'admin';
my ($passwd) = 'admin';
my ($ena)='enable';
my ($conf)='conf t';
my ($command1)='hostname R2D2';
my ($command2)='exit';
my ($command3)='wr mem';
  
 $t = new Net::Telnet (Timeout => 10, Telnetmode => 1,  Input_Log => "infile.log", Output_log => "output.log",);
           $t->open("$lines");
           $t->waitfor('/login:$/i');
           $t->print($username);
           $t->waitfor('/Password:$/i');
           $t->print($passwd);
       $t->print ("$ena");
       $t->print ("$conf");
       $t->print("$command1");
       $t->print("$command2");
       $t->print("$command3");
       $t->print("$command2");

When you run the script, it says problem connecting to "" port 23.
Ie . the script does not extract the line with the address from iplist.txt
For the loop, as I understand it, you will need to use something like:
while (@ lines = "<IPlist>") 
 {
           $t->open("$lines");
           $t->waitfor('/login:$/i');
           $t->print($username);
           $t->waitfor('/Password:$/i');
           $t->print($passwd);
       $t->print ("$ena");
       $t->print ("$conf");
       $t->print("$command1");
       $t->print("$command2");
       $t->print("$command3");
       $t->print("$command2");
}
close ( IPlist );

but then the script just hangs.
PS Commands are written for an example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypt3r, 2015-02-25
@sh1kima26

open my ($ip) = (IPlist, "iplist" or die "can't open iplist: $!");
my ($username) = 'admin';
while (@ lines = "<IPlist>")

Well, you write nonsense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question