455,848 Members | 1,363 Online
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

# some usage doubts on net::telnet

 100+ P: 170 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 use Net::Telnet;   $telnet3 = new Net::Telnet;$telnet3->open('IP_ADDRESS'); # Substituted fake IP $telnet3->waitfor('/Enter login:$/i'); $telnet3->print('USERNAME'); # Substituted fake User$telnet3->waitfor('/Enter password: $/i');$telnet3->print('PASSWORD'); # Substituted fake PW   print "Logged in to device\n";   Apr 16 '08 #1
21 Replies

 Expert Mod 2.5K+ P: 3,503 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 use Net::Telnet;   $telnet3 = new Net::Telnet;$telnet3->open('IP_ADDRESS'); # Substituted fake IP $telnet3->waitfor('/Enter login:$/i'); $telnet3->print('USERNAME'); # Substituted fake User$telnet3->waitfor('/Enter password: $/i');$telnet3->print('PASSWORD'); # Substituted fake PW   print "Logged in to device\n";   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

 100+ P: 170 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 use Net::Telnet;   $telnet3 = new Net::Telnet(timeout => 10, Errmode => 'die');$telnet3->open('IP_ADDRESS');  $telnet3->login(username, password); @lines =$telnet3->cmd("who");     open(FILE, ">file.txt");       print FILE ("@lines\n");   Apr 17 '08 #3

 Expert 100+ P: 410 You can catch the errors as below: Expand|Select|Wrap|Line Numbers $telnet3->open('IP_ADDRESS') or die "failed to connect:$!";  $telnet3->login(username, password) or die "login failed:$!";   Apr 17 '08 #4

 100+ P: 170 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

 Expert 100+ P: 410 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 $telnet3 = new Net::Telnet(timeout => 10, Errmode => 'return'); Apr 17 '08 #6  100+ P: 170 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  Expert 2.5K+ P: 4,059 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 c:\>perl yourscript.pl provide full paths if necessary Expand|Select|Wrap|Line Numbers c:\>Perl\bin\perl.exe path\to\yourscript.pl then press enter and the windows will stay open. Apr 17 '08 #8  100+ P: 170 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  100+ P: 170 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

 Expert 2.5K+ P: 4,059 instead of : Expand|Select|Wrap|Line Numbers $telnet3 = 'foobar'; you need to declare it with "my": Expand|Select|Wrap|Line Numbers my$telnet3 = 'foobar'; Thats what the error message you are getting means. Apr 17 '08 #11

 100+ P: 170 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

 Expert Mod 2.5K+ P: 3,503 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

 100+ P: 170 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

 Expert Mod 2.5K+ P: 3,503 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

 100+ P: 170 ok thanks hm..i've already done some verifying Expand|Select|Wrap|Line Numbers     my ($t); use Net::Telnet ();$t = new Net::Telnet;        $t->open("IP_ADDRESS");$t->waitfor( -match => qr{ogin});      $t->print("USERNAME");$t->waitfor( -match => qr{assword});      $t->print("PASSWORD"); @lines =$t -> getlines (timeout=>20);     print @lines;   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

 Expert 100+ P: 410 Not sure if prompt matching is the cause. But if it is, try to use prompt matching as below: Expand|Select|Wrap|Line Numbers     $t->waitfor('/login:/i');$t->print($user);$t->waitfor('/password: $/i');$t->print($passwd); Apr 18 '08 #17  100+ P: 170 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 #!perl\bin\perl use strict; use warnings; my$t;    my $string; my$data;       use Net::Telnet();      $t = new Net::Telnet;$t->open("password"); #replace with yr own ip      $t->waitfor('/ENTER USERNAME < /i');$t->print("username"); #replace with yr own username      $t->waitfor('/ENTER PASSWORD < /i');$t->print("password"); #replace with yr own password      @lines = $obj->getlines (timeout=1500); print @lines; 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  Expert 2.5K+ P: 4,059 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 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 Timeout => nnn The code you posted should not even compile as you have not declared all of your variables properly. Apr 21 '08 #19  100+ P: 170 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 #!perl\bin\perl use strict; use warnings; my$t;    my @lines;         use Net::Telnet();      $t = new Net::Telnet;$t->open("ip_Address");      $t->waitfor('/ENTER USERNAME < /i');$t->print("username");      $t->waitfor('/ENTER PASSWORD < /i');$t->print("password");      @lines=\$t->getlines(timeout=>1500);      print @lines;   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

 Expert 2.5K+ P: 4,059 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

 100+ P: 170 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