Dear all,
I have written following script to loin to router bu it is showing error. -
#!c:\Perl\bin;
-
use strict;
-
use warnings;
-
-
my $hostname = 'REMOVED FOR YOUR PROTECTION';
-
my $password = 'REMOVED FOR YOUR PROTECTION';
-
-
use Net::Telnet();
-
my $telnet = new Net::Telnet ( Timeout=>40,Errmode=>'die');
-
$telnet->open($hostname);
-
$telnet->waitfor('/Password: $/i');
-
print ("printing password");
-
$telnet->print($password);
-
$telnet->waitfor('/Router> $/i');
-
print ("getting admin rights");
-
$telnet->print('en');
-
$telnet->waitfor('/Password: $/i');
-
$telnet->print($password);
-
print ("printing password");
-
$telnet->waitfor('/Router#: $/i');
-
Can't locate object method "new" via package "Net::Telnet" (perhaps you forgot t
o load "Net::Telnet"?) at h.pl line 9.
pls help me to rectify the problem
17 7048 @ravimath
Try removing the parenthesis after the module name, as such:
They are not needed and are probably causing your problem.
Also, please do not include sensitive information in your posts (such as login information and IP Addresses). That is a security risk that you should always be wary of. I have removed them for you in your post.
Regards,
Jeff
I have tried removing parenthesis, but still it gives same error.
thanks for your help
Did you properly install the Net::Telnet module? Your code is right out of the modules example code so that shouldn't be the problem, so maybe the module installation wasn't done properly.
can u tell me how to check whether i have installed install the Net::Telnet module properly or not ? rather tell me how to install install the Net::Telnet module.
I have read cpan.faq , but it is not having sufficient info , regarding net::telnet installation on windows platform using ppm or any other method
can u tell me how to check whether i have installed install the Net::Telnet module properly or not ? rather tell me how to install install the Net::Telnet module.
pls help
i have resolved following problemCan't locate object method "new" via package "Net::Telnet" (perhaps you forgot t
o load "Net::Telnet"?) at h.pl line 9., but now when i run that original script
it waits for getting input and after getting input it gives following error
'sfddg' is not recognized as an internal or external command,
operable program or batch file.
when i type something it shows nothing on screen , but it takes input.
even when i run another small script which includesonly one line
print $wkday;
it just returns to command prompt and does not show anything on screen
2)can u suggest some modifications, i want to achieve following
It should prompt for ip address of router , then ask for username , password and enable password and finally it should give output on screen of sh run of that router
@ravimath
For the modifications in #2, that should be quite simple for you to add. Why not try and post your code if you get stuck. Its just a simple matter of prompting the user and storing the answer(s).
Regards,
Jeff
-
#!c:\Perl\bin;
-
use strict;
-
use warnings;
-
-
my $hostname = 'REMOVED FOR YOUR PROTECTION';
-
my $password = 'REMOVED FOR YOUR PROTECTION';
-
-
use Net::Telnet();
-
my $telnet = new Net::Telnet ( Timeout=>40,Errmode=>'die');
-
$telnet->open($hostname);
-
$telnet->waitfor('/Password: $/i');
-
print ("printing password");
-
$telnet->print($password);
-
$telnet->waitfor('/Router> $/i');
-
print ("getting admin rights");
-
$telnet->print('en');
-
$telnet->waitfor('/Password: $/i');
-
$telnet->print($password);
-
print ("printing password");
-
$telnet->waitfor('/Router#: $/i');
-
I have already added this code pls suggest changes for my previous question
That should be simple. -
print "\nEnter Router IP:";
-
$hostname=<STDIN>;
-
print "\nEnter password:";
-
$password=<STDIN>;
-
Ravimath, you need to PLEASE use code tags around your code that you put into the forums. It is not optional and is required. If you do not do it, we have to clean up behind you. If you notice your original post, you will see I did it there as well.
Regards,
Jeff
what is code tags ? pls help regarding this . i am sorry b
coz i am new to this
Code tags are used to distinguish plain text from Perl code snippets
in your posting. They help others to more clearly understand your question.
When you are typing your question into this forum, you should see
several icons above the box where you are typing. The icon that looks
like # will automatically add a pair of CODE tags for you.
It would also help others to more clearly understand your question
if you used full English words rather than abbreviations. For example,
"please" is clearer than "pls".
In addition, here is a link to the posting guidelines for asking a question, which fully explains code tags.
Regards,
Jeff
I am attaching two small programs
1) - #!c:\Perl\bin\perl;
-
-
use warnings;
-
my $hostname = 'x.x.x.x';
-
use Net::Telnet;
-
my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
-
print("connected");
-
$telnet->open($hostname);
-
-
$telnet->print('username');
-
$telnet->print('password');
-
$telnet->print('show run ');
2) - #!c:\Perl\bin;
-
use strict;
-
use warnings;
-
use Net::Telnet;
-
my $telnet = new Net::Telnet ( Timeout=>30,Errmode=>'die');
-
$telnet->open('x.x.x.x');
-
$telnet->login('Username', 'Password');
-
print "ok";
-
$telnet->cmd('who');
-
-
timed-out waiting for command prompt at h7.pl line 7
for the first program it is not showing any error it just gives output connected
but it will not give any output of show run
for second program it is showing error as above,
please suggest changes
For the first program, the 'print' method only passes the command to telnet. It will not display the result on your console. If you want the result on console, use 'cmd' method to capture result. Alternately, you can use 'Output_log' and 'Input_log' options to save input & output of telnet session to a log file. -
my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die',Input_log => 'input.txt, Output_log=> 'output.txt');
-
print("connected");
-
$telnet->open($hostname);
-
-
$telnet->print('username');
-
$telnet->print('password');
-
my @res= $telnet->cmd('show run ');
-
print "@res";
-
For the second program, the problem may be that the command prompt that script is waiting for did not match with the one that it found(you can set the 'Prompt' option for 'cmd' and 'new' methods).
Else, you can use a combination of 'waitfor' and 'print' methods. -
$telnet->waitfor('/login: /'); # put the prompt that you get(inside //)
-
$telnet->print($username);
-
$telnet->waitfor('/password:/');
-
$telnet->print($pass);
-
Hi all,
I have written following script. - use Net::Telnet;use Term::ReadKey;@a=('x.x.x.x' ,'x.x.x.x);@b=('host1','host2' );$i=0; print "Enter username\n";$user = <STDIN>;chomp($user);ReadMode( "noecho", STDIN );print "Enter password\n";$pwd = <STDIN>;chomp($pwd);ReadMode ("original", STDIN) ; $epwd='password';while ($i<2){$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');$telnet->open($a[$i]); $telnet->waitfor('/Username:/');$telnet->print($user);
-
$telnet->waitfor('/Password:/');$telnet->print($pwd);$h=$b[$i].'>';$e=$b[$i].'#';open(MYOUTFILE, ">>PriStatus.txt");$telnet->waitfor('/'.$h.'/'); $telnet->print('en');$telnet->waitfor('/Password:/');$telnet->print($epwd);print $epw;$telnet->waitfor('/'.$e.'/');$telnet->print('sh int desc | inc PRI');@lines=$telnet->waitfor('/'.$e.'/');print MYOUTFILE @lines;print @lines;$telnet->print('sh run | inc dialer string');@lines=$telnet->waitfor('/'.$e.'/');print MYOUTFILE @lines;print @lines;$telnet->close;$i++; }
In the above script i am logging in to each router and getiing PRI status and storing it in some text file , it works fine1)but how to telnet to router without using hostname 2)if first router is not reachable still it should move on to next router in the array , how to check whether it is reachable or not ?3)@lines vaiable stores only 255 bytes , if i want to store large data ( e.g show run ) how to achieve it.
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
6 posts
views
Thread by Richard Bird CCNP, CCDP, MCSE, etc. |
last post: by
|
2 posts
views
Thread by john brown |
last post: by
|
2 posts
views
Thread by newsf |
last post: by
|
3 posts
views
Thread by Lidvar |
last post: by
|
2 posts
views
Thread by _andrea.l |
last post: by
|
reply
views
Thread by mario.lat_ |
last post: by
|
2 posts
views
Thread by vmalhotra |
last post: by
| | | | | | | | | | | | |