473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

some usage doubts on net::telnet

170 100+
hi guys,
a question on net::telnet
what does this module do?
cos i have a telnet client that will be able to communicate with a database
so is it true if i enter my ip address, username, and password and using print later again to execute some commands
i will get some results on some screen??



Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2.  
  3. $telnet3 = new Net::Telnet;
  4. $telnet3->open('IP_ADDRESS'); # Substituted fake IP
  5. $telnet3->waitfor('/Enter login: $/i');
  6. $telnet3->print('USERNAME'); # Substituted fake User
  7. $telnet3->waitfor('/Enter password: $/i');
  8. $telnet3->print('PASSWORD'); # Substituted fake PW
  9.  
  10. print "Logged in to device\n";
  11.  
Apr 16 '08 #1
21 2761
numberwhun
3,509 Expert Mod 2GB
hi guys,
a question on net::telnet
what does this module do?
cos i have a telnet client that will be able to communicate with a database
so is it true if i enter my ip address, username, and password and using print later again to execute some commands
i will get some results on some screen??



Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2.  
  3. $telnet3 = new Net::Telnet;
  4. $telnet3->open('IP_ADDRESS'); # Substituted fake IP
  5. $telnet3->waitfor('/Enter login: $/i');
  6. $telnet3->print('USERNAME'); # Substituted fake User
  7. $telnet3->waitfor('/Enter password: $/i');
  8. $telnet3->print('PASSWORD'); # Substituted fake PW
  9.  
  10. print "Logged in to device\n";
  11.  
If you read the page, you will find that the print() function of that module will write what you put in there, specifically after the connection is made. What you want is the login() function to log in. The CPAN page shows you how to use this module.

Regards,

Jeff
Apr 16 '08 #2
poolboi
170 100+
hi guys,
alright i tried to see if my connection works using the following code
but when i use the program it apparents open the perl command line interpreter that just waits for some time before closing the interpreter

i dunno what was happening but apparently my guess it timeout cos there's some errors

is there any way to check if i'm connected to the IP i stated?

Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2.  
  3. $telnet3 = new Net::Telnet(timeout => 10,
  4.                 Errmode => 'die');
  5.  
  6. $telnet3->open('IP_ADDRESS'); 
  7. $telnet3->login(username, password);
  8. @lines = $telnet3->cmd("who");
  9.  
  10.  
  11. open(FILE, ">file.txt");
  12.  
  13.     print FILE ("@lines\n");
  14.  
Apr 17 '08 #3
nithinpes
410 Expert 256MB
You can catch the errors as below:

Expand|Select|Wrap|Line Numbers
  1. $telnet3->open('IP_ADDRESS') or die "failed to connect:$!"; 
  2. $telnet3->login(username, password) or die "login failed:$!";
  3.  
Apr 17 '08 #4
poolboi
170 100+
hm..tried that
still the same
like a the perl interpreter screen comes up
and after the default timeout of 10
the screen closes
no errors caught and i still got no idea if connection is made
pls help
Apr 17 '08 #5
nithinpes
410 Expert 256MB
hm..tried that
still the same
like a the perl interpreter screen comes up
and after the default timeout of 10
the screen closes
no errors caught and i still got no idea if connection is made
pls help
Before trying to catch the error, you need to change Errmode in the line where you are creating new instance of object.

Expand|Select|Wrap|Line Numbers
  1. $telnet3 = new Net::Telnet(timeout => 10,
  2.                 Errmode => 'return');
  3.  
  4.  
Apr 17 '08 #6
poolboi
170 100+
right..i've actually done what u have said to try and catch the error
but i think there's a problem
the screen display the error and then closes it in 1 sec
it's almost impossible to see the error msg
any one experience this kind of problem before?
i'm using activestate perl 5.10 on windows XP
Apr 17 '08 #7
KevinADC
4,059 Expert 2GB
check your Windows firewall ( or any other one you may have running) and see if it is blocking telnat access. If you don't know how to check consult your Windows XP help files.

Also, don't double-click on your perl file to run it. Open a DOS window and type in:

Expand|Select|Wrap|Line Numbers
  1. c:\>perl yourscript.pl
provide full paths if necessary

Expand|Select|Wrap|Line Numbers
  1. c:\>Perl\bin\perl.exe path\to\yourscript.pl
then press enter and the windows will stay open.
Apr 17 '08 #8
poolboi
170 100+
thanks for the help
ok
right now the error msg is i can't login with the username and password
i got no idea why
it isn't blocked by any firewalls
and when i telnet using the command prompt using the same password and username it is able to log into my telnet application
any idea why i can't log in when i use net::telnet??
Apr 17 '08 #9
poolboi
170 100+
alright here's the warning message
i dunno if it helps

the warning mesage is

"global symbol $telnet3 requires explicit package name"
Apr 17 '08 #10
KevinADC
4,059 Expert 2GB
instead of :

Expand|Select|Wrap|Line Numbers
  1. $telnet3 = 'foobar';
you need to declare it with "my":

Expand|Select|Wrap|Line Numbers
  1. my $telnet3 = 'foobar';
Thats what the error message you are getting means.
Apr 17 '08 #11
poolboi
170 100+
OK
everything's fine but i guess the login has some problem
it alwayss time out at the login line
i read that i need to input some kind of prompt like bash
but i know that's for linux
does this prompt makes the differences on windows XP such that it can't read my login?
i really dunno why it's not logging in
pls help look into this? thank you
Apr 17 '08 #12
numberwhun
3,509 Expert Mod 2GB
OK
everything's fine but i guess the login has some problem
it alwayss time out at the login line
i read that i need to input some kind of prompt like bash
but i know that's for linux
does this prompt makes the differences on windows XP such that it can't read my login?
i really dunno why it's not logging in
pls help look into this? thank you
My suggestion then, is to just do a telnet from the command line and see if it works. If not, then you need an account on that other machine. Also, make sure the other machine is allowing telnet as well.

Regards,

Jeff
Apr 17 '08 #13
poolboi
170 100+
yup
it's allowing me to enter into the switch
i'm telnetting into a switch basically
from command line it can be done
how ever from the module net::telnet
i can't seem to log it in...i got no idea why

u might ask why i'm doing this rather from command line..
basically i'm creating a script to communicate one data base to another proprietary database
and the proprietary database can only be logged in by telnetting into the swtich
so the i still can't establishing a connection using net::telnet...
so any clues?
:)
Apr 18 '08 #14
numberwhun
3,509 Expert Mod 2GB
yup
it's allowing me to enter into the switch
i'm telnetting into a switch basically
from command line it can be done
how ever from the module net::telnet
i can't seem to log it in...i got no idea why

u might ask why i'm doing this rather from command line..
basically i'm creating a script to communicate one data base to another proprietary database
and the proprietary database can only be logged in by telnetting into the swtich
so the i still can't establishing a connection using net::telnet...
so any clues?
:)
Not having done much of anything (at all) with this module, I am not sure why you aren't able to log in. I would re-read the module documentation and see if there is anything you may have missed.

Regards,

Jeff
Apr 18 '08 #15
poolboi
170 100+
ok thanks
hm..i've already done some verifying

Expand|Select|Wrap|Line Numbers
  1.     my ($t);
  2.  
  3.     use Net::Telnet ();
  4.  
  5.     $t = new Net::Telnet;
  6.  
  7.      $t->open("IP_ADDRESS");
  8.      $t->waitfor( -match => qr{ogin});
  9.      $t->print("USERNAME");
  10.      $t->waitfor( -match => qr{assword});
  11.      $t->print("PASSWORD");    
  12.     @lines = $t -> getlines (timeout=>20);
  13.     print @lines;
  14.  
to print out what happens when i log in
so when i "telnet IP_ADDSRESS"
it brings me to a page with ENTER USERNAME <
i manage to get the lines out when i print this
but when i started testing it with my login and password
nothing came out
cos it's suppose to like print "WELCOME TO DIALOGUE SESSION"

but nothing came out...
so i'm just wondering it could be the prompt matching that's causing the problem
the password and username aren't caught by the program
so see if anyone of u can detect the problem
Apr 18 '08 #16
nithinpes
410 Expert 256MB
Not sure if prompt matching is the cause. But if it is, try to use prompt matching as below:

Expand|Select|Wrap|Line Numbers
  1.     $t->waitfor('/login:/i');
  2.     $t->print($user);
  3.  
  4.     $t->waitfor('/password: $/i');
  5.     $t->print($passwd);
  6.  
Apr 18 '08 #17
poolboi
170 100+
hi nithinpes
alright i've got it to log in with yr code
perhaps u can have a look below:

Expand|Select|Wrap|Line Numbers
  1. #!perl\bin\perl
  2. use strict;
  3. use warnings;
  4.  
  5.   my $t; 
  6.   my $string;
  7.   my $data;
  8.  
  9.     use Net::Telnet(); 
  10.     $t = new Net::Telnet;
  11.  
  12.      $t->open("password"); #replace with yr own ip
  13.      $t->waitfor('/ENTER USERNAME < /i');
  14.      $t->print("username"); #replace with yr own username
  15.      $t->waitfor('/ENTER PASSWORD < /i');
  16.      $t->print("password"); #replace with yr own password
  17.      @lines = $obj->getlines (timeout=1500);
  18.      print @lines;
  19.  
so i use the code getlines to print out what i got on the screen so as to verify i got logged in
hm..
but the problem is i needed to use 1500 secs before i can it printed out
i think that's gonna pose a problem since it's taking such a long time
u all know why it's taking such a long long time to get the results printed out?
Apr 21 '08 #18
KevinADC
4,059 Expert 2GB
Judging by your code I am confused if you are reading the Net::Telnet documentation.

Question: Where in it do you see this:

Expand|Select|Wrap|Line Numbers
  1. timeout=nnn
where nnn is any number.

Answer: You don't. Read the documentation and pay careful attention to the syntax:

Expand|Select|Wrap|Line Numbers
  1. Timeout => nnn
The code you posted should not even compile as you have not declared all of your variables properly.
Apr 21 '08 #19
poolboi
170 100+
opps i forgot to amend the mistakes before posting
it was the previous code

alright here's the right one
Expand|Select|Wrap|Line Numbers
  1. #!perl\bin\perl
  2. use strict;
  3. use warnings;
  4.  
  5.   my $t; 
  6.   my @lines;
  7.  
  8.  
  9.     use Net::Telnet(); 
  10.     $t = new Net::Telnet;
  11.  
  12.      $t->open("ip_Address");
  13.      $t->waitfor('/ENTER USERNAME < /i');
  14.      $t->print("username");
  15.      $t->waitfor('/ENTER PASSWORD < /i');
  16.      $t->print("password");
  17.      @lines=$t->getlines(timeout=>1500);
  18.      print @lines;
  19.  
hm..ok this should be right
yeap so my question will still be
why does it take like 1500 secs to return me the results, lesser than that
it times out

cos usually when i telnet using command prompt, they ask for username and password, then i enter into my switch control
is it cos the @lines started reading line the moment i log into my switch? that's why it's taking a long time to read all the lines when i log into my switch
Apr 21 '08 #20
KevinADC
4,059 Expert 2GB
so my question will still be
why does it take like 1500 secs to return me the results, lesser than that
it times out

cos usually when i telnet using command prompt, they ask for username and password, then i enter into my switch control
is it cos the @lines started reading line the moment i log into my switch? that's why it's taking a long time to read all the lines when i log into my switch
I have no idea why it takes that long.
Apr 21 '08 #21
poolboi
170 100+
hm..ok thanks
but if anyone let me know
i guess for now i'll just do some testing and seee if it affects my development
i'm doing connections with mysql and telnet now
after which i will merge them up
iso if anyone knows just respond
many thanks :)
Apr 21 '08 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pete Johansen | last post by:
Hi Folks, This prompt statement has been a real pain in the the butt. I am using net::telnet(v3.03) to connect to a W2K box from a Solaris 2.6 box. I the output stream resulting from a 'dir'...
2
by: Vinay Gupta | last post by:
Hi, In a Perl to Tcl conversion project, I am planning to use the following Tcl extensions as a replacement for some Perl libraries. My development environment is Windows. Win32::OLE --> "DDE"...
1
by: kriz4321 | last post by:
Hi all, This is the code I use to login to any device.( I will not be able to see any window but it will be able to login to the device and give the command specified)... can you tell me what...
1
by: jyohere | last post by:
I want to login to a remote machine using Net::Telnet....then i want to move to a particular directory in that remote machine....after that i want to get a list of files under that directory....after...
0
by: shineyang | last post by:
Dear all: Who is kind to help me about the following problem. Why cannot log the remote node by using Net::Telent #################################### The following is normal to the process...
3
by: surajsingh | last post by:
Hi, I have a perl script which uses Net::Telnet module to open a telnet session with my unix boxes, and executes lot of commands on those boxes. As this module is implemented, when 'cmd' is...
2
by: kriz4321 | last post by:
Hello all i am using net:telnet module to login to the remote machine and execute some commands and to collect some logs corresponding to the command given. After loging into the machine I do...
0
by: SteveBark | last post by:
Any pointers on this truly appreciated. I am using net::telnet to connect to a modem pool and then connect with a remote piece of kit. Everything works fine normally, however on occassions the...
1
by: abdulbca | last post by:
Hi, I am trying to execute a simple perl script, i have installed net::telnet module. I have many perl scripts and all are running fine, except this first perl script i m trying to write for net...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.