|
amir | Posted at 6:22am on Thursday, March 8th, 2007 |
too good |
Xose | Posted at 3:39am on Friday, March 23rd, 2007 |
good |
Anonymous | Posted at 4:54am on Thursday, March 29th, 2007 |
easily understandable + short = Very GOOD introduction |
don | Posted at 3:22pm on Wednesday, April 4th, 2007 |
good and easy to start a telnet in perl |
Chris | Posted at 3:33am on Friday, April 6th, 2007 |
Hello...
i have aquestion related to this Script. You connect to a host. Do you disconnect also? No, or?
thx |
Ninomninom | Posted at 4:07pm on Tuesday, April 17th, 2007 |
thanks for this document i was looking for an explantion for waitfor and i saw this site and it is explaining ver well. Thanks |
Gimi | Posted at 1:53pm on Wednesday, April 18th, 2007 |
Runing yous scrips i have this error
pattern match timed-out at |
Ajay | Posted at 11:57pm on Monday, April 23rd, 2007 |
can i connect to remote windows 2000 machine using NET::TELNET, as i'm not able to connect , actaully it is returing Junk, But same script is running perfectly fine on Windows XP machine ???????????// |
aliaz | Posted at 12:08pm on Friday, April 27th, 2007 |
I can't connect to windows 2000 server also
there 3 prompte
USERCODE:
PASSWORD
DOMAIN:
my code send me time out saying that the pattern /domain[: ]*/ can't be match |
sirc | Posted at 6:18pm on Sunday, May 27th, 2007 |
how can i handle the connection error.. if the machine im connecting to is down? how can i catch the error? |
Tom | Posted at 1:32pm on Tuesday, July 10th, 2007 |
Hi.
I have tried this code but I have recieved an error when I'm executing the script: "pattern match timed-out at line 38".
Line 38 is $telnet->waitfor('/$ $/i');
Someone can helping me solving this ? |
djs | Posted at 4:33pm on Monday, July 16th, 2007 |
you are not matching a prompt. it looks like you forgot to escape out your $, try this:
$telnet->waitfor('/$ $/i'); |
ob1 | Posted at 2:01pm on Wednesday, July 18th, 2007 |
do we need to send an initial carriage return if connecting to a terminal server? it seems to need this before a login prompt is displayed. |
ob1 | Posted at 3:53pm on Wednesday, July 18th, 2007 |
never mind my previous post. print and waitfor combo worked great. thanks for a clear and concise article. |
trying to run shell scripts | Posted at 8:24am on Thursday, July 19th, 2007 |
Hi I was having problem running shell scripts
So the only way I got it to work was by estimating the time it takes to run so if it ran for 10 sec
I put a sleep 12 and then it worked. I sthere a way to do this without putting sleep commands, I thought the wait for would handle this. |
nicky | Posted at 11:25pm on Tuesday, August 7th, 2007 |
hi cool artical
can i ask some question?
what does $telnet->waitfor('/$ $/i'); do?
i dont really understand wat '/$ $/i' means u see
also isnt possible to write the result of the
$telnet->print('who');
into a notepad in my c drive? if so how would the code be like? |
hb | Posted at 7:44am on Wednesday, August 8th, 2007 |
Thank you for help! perldoc Net::Telnet was not so clear for me before.
In my script I have writen :
(translated to your example )
@output = $telnet->waitfor('/$ $/i'); print @output;
compare with :
$output = $telnet->waitfor('/$ $/i'); print $output; |
RR | Posted at 2:48pm on Wednesday, August 8th, 2007 |
I am having problem in connecting to the server
'timed-out waiting for command prompt at C:perl temptelnet.pl line 10'
although i am giving the same username and paasword that i am using manually.
Can someone help me out here |
manoj | Posted at 5:59am on Thursday, August 9th, 2007 |
I am facing problem.
i am executing command "cat test.txt" on remote machine through this module.this file contain number of lines & each line having numbers of fields, each of them seperated by tab.
when i get the output of that command & i try to split each line using tab as seperator.it does not work (split does not find tab in the line).
can some one haelo me. its urgent |
Aparna | Posted at 12:06am on Friday, August 17th, 2007 |
really good and made telnet easy thru perl |
thaha | Posted at 4:57am on Wednesday, August 29th, 2007 |
thanks a lot to provide such a nice intro to the telnet thru perl. |
downloadsoftware.com@gmail.com | Posted at 3:05am on Friday, September 7th, 2007 |
port 23 connection failed |
bdizzel | Posted at 1:13pm on Tuesday, September 18th, 2007 |
i was curious on what /$ $/i means any ideas? |
Mark | Posted at 11:45pm on Tuesday, September 18th, 2007 |
bdizzel ....
You mean waitfor('/$ $/i');?
I guess that this is waiting for the prompt "$ " (dollar, space). Note that the first dollar is escaped so it is interpreted as a character. The last dollar indicates end of line. |
bdizzel | Posted at 11:03am on Thursday, September 20th, 2007 |
thank you mark, i also have another question, when i used the command print $telnet->cmd('who'); , the very last line of the print is my prompt i recieve after i log in- bash2-:03$ ... i was wondering if there is a way to get that out of there, i was thinking about using chop or chomp but no success there... any help is appreciated thank you in advanced |
McNally | Posted at 9:40am on Monday, September 24th, 2007 |
For those who are confused reading the comments so far -- it appears to me that the commenting system is eating backslashes. Compare what's being displayed in the comments from bdizzel and others (i.e.: '/$ $/i') with what's in the code box in the article above -- you will find that in the latter there is an extra backslash character present before the first "$" to escape its special meaning as an end-of-line anchor in the pattern match. What the author is trying to match is the sequence (dollar sign)(space)(end-of-line). What the version without the backslash tries to match is (end-of-line)(space)(end-of-line), which is obviously much different.
Also, keep in mind that the prompt string that they're trying to match only makes sense if your prompt ends with a dollar sign ($) -- if you use a csh derivative, for example, and use the convention that your prompt ends in a percent sign (%) or if you like to feel importantly root-like and end your prompt with an octothorpe (aka (in US usage) pound sign, aka "#") -- well, then, you'll have to change your match expression.
Does that clear it up, bdizzel? |
bdizzle | Posted at 8:02am on Thursday, September 27th, 2007 |
excellent work McNally, i appreciate you taking the time to respond to my question, the prompt was confusing but this pretty much clears it up- thanks again |
tez | Posted at 3:43am on Friday, September 28th, 2007 |
Hi
I too am having problems with the sequence match. I am using TACACS on my Cisco equipment and have a multi line banner message that finishes with "Usercode:". I have tried all sorts of variations but I stil lfail to get it to work. For example.. waitfor('/[: ]*$/i'); I have tried a number of variations, can anyone help me at all? |
sumant chhunchha | Posted at 7:25am on Monday, October 8th, 2007 |
Hello,
I tried the things as above...I am trying to telnet with application port which is 2101..when i directly try from dos prompt as >telnet 2101.....it opens a telnet connection and I can fire command for that application however ere it is not showing any prompt to me..it shows blank scree and then i fire commands related to that. however using script it shows error "timed-out waiting for login prompt at telnet2.pl line 18"..... what can be the solution?
[code]
$telnet = new Net::Telnet ( Port=> 2101, Timeout=>10, Errmode=>'die');
$telnet->open('ps4131');
$telnet->login('administrator', 'password');
peint $telnet;
[/code] |
Sumit | Posted at 7:47pm on Friday, October 26th, 2007 |
hi my prompt is someting like
host:user:dir>
please help me setting the prompt =>'' pattern
I tried alot but nothing doing :( |
Sumit | Posted at 7:48pm on Friday, October 26th, 2007 |
hi my prompt is someting like
host:user:dir>
please help me setting the prompt =>'' pattern
I tried alot but nothing doing :( |
Mikael | Posted at 7:23pm on Friday, November 2nd, 2007 |
I think host:user:dir> would be as simple as:
$telnet->waitfor('/^host:user:dir>$/'); |
Salih | Posted at 11:47am on Tuesday, November 20th, 2007 |
I have tried the code above several times . The steps of code are run succesfully untill it reaches line 8 where waitfor() is.
here is my command prompt during connection.
login:
Password:
switch8-12>
The perl script i coded.
1-use Net::Telnet;
2-$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');
3-$telnet->open('192.168,0,12');
4-$telnet->waitfor('/login:/');
5-$telnet->print('salih');
6-$telnet->waitfor('/Password:/');
7-$telnet->print('S132A13');
8-$telnet->waitfor('/switch8-12>/');
9-$telnet->print('who');
10-output=$telnet->waitfor('/switch8-12>/');
11-print $output;
Wating for your comments.
Thanks in advance.
Cheers...
All for one, one for all.
(i think that is enough :)))) ) |
duke74s | Posted at 4:42am on Monday, December 3rd, 2007 |
hi my prompt is like this
"[root@z1 ~]# "
- root : user, z1 : hostname, ~ : directory
I've never find the pattern. Please, help me!! |
ptg | Posted at 9:31am on Monday, December 3rd, 2007 |
I need to run the telnet script against devices with differnt login methods (individual useraccounts and direct password accounts).
Method1:
Username:xxx
Password:xxx
router#
Method2:
Password:xxx
router>enable
Password:xxx
router#
can we do a if and else using telnet->waitfor?
if ($telnet->waitfor('/Password: $/i')) {
$telnet->print("$ARGV[3]");
$telnet->waitfor('/>$/i');
$telnet->print('enable');
$telnet->waitfor('/Password: $/i');
$telnet->print("$ARGV[4]");
$telnet->waitfor('/#$/i');
$output = $telnet->print('');
}
else {
$telnet->waitfor('/Username: $/i');
$telnet->print("$ARGV[3]");
$telnet->waitfor('/Password: $/i');
$telnet->print("$ARGV[4]");
$telnet->waitfor('/#$/i');
$output = $telnet->print('');
}
Any help would be must appreciated!!! thanks!!! |
RRP | Posted at 5:10am on Thursday, January 3rd, 2008 |
HI Dear,
I found the following error message while trying to connect via telnet. I do not understand what is INC and what it does. I serched but did not find anything. Please help me on this. I am using windows XP. Is there any setting needs to be done for INC.
C:PerlsitelibURI>perl test2.pl
Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at test2.pl line 4.
BEGIN failed--compilation aborted at test2.pl line 4. |
kwatkins | Posted at 1:27pm on Thursday, January 3rd, 2008 |
Great, thanks |
John Ryan | Posted at 11:11am on Tuesday, January 8th, 2008 |
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
$telnet->open('168.54.24.155');
$telnet->waitfor('/login: $/i');
$telnet->print('jryan');
$telnet->waitfor('/Password: $/i');
$telnet->print('5JKD223WER1');
$telnet->waitfor('/# $/i');
$telnet->print('uname -a');
$output = $telnet->waitfor('/# $/i');
print $output;
----------
doesn't matter what command I use (in the case above it is uname -a) it always return "1". what does it mean and how to fix it? |
sujith | Posted at 1:17am on Wednesday, January 9th, 2008 |
when i run this same program to connect to my server it return some error..
The error seems to be like this....
problem connecting to "192.168.1.100", port 23: Connection refused
Can any one help me out ..
cheers |
Rami | Posted at 1:08am on Tuesday, January 15th, 2008 |
Great ! :) now how to compile it ?? |
Thommy | Posted at 6:52am on Tuesday, January 22nd, 2008 |
My Problem:
setting up a couple of devices via a Cisco Terminal Server.
I want to plug for example 5 Switches to this terminalserver 10.1.1.1 Port 2002 up to 2007
Then i want to set up the Vlan Interface and getting the configuration file from a tftp server.
But my main Problem is to execute commands on the terminal line because i have no login with a terminal server console.
My code:
my $session = Net::Telnet::Cisco::IOS->new(Host => '10.1.1.1', Port => 2002);
$session->cmd("nn"); # for getting a promt without login
@output = $session->cmd('sh run');
print @output;
but command ($session->cmd("nn");)timed-out at test.pl
I tried the same with a regular telnet session to a router and a login, this works
Can u help me? |
Serge | Posted at 6:50am on Wednesday, January 23rd, 2008 |
Thanks a lot! |
shree | Posted at 3:09am on Tuesday, January 29th, 2008 |
Actually i tried the below program:
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'die');
$telnet->open('180.15.24.13');
# change this according to your telnet prompt
$telnet->waitfor('/login:/');
$telnet->print('root');
#change this according to your telnet password prompt
$telnet->waitfor('/Password:/');
$telnet->print('siemens');
# $telnet->waitfor('/sun4#/'); #change this to the prompt of the user you are testing
#print $telnet->cmd('./testing.sh');
#print $telnet->cmd('echo " hello " >> hello.csv');
$telnet->close();
but got an error in the command prompt saying:
Can't locate Net/Telnet.pm in @INC (@INC contains: d:/Perl/lib d:/Perl/site/lib .) at telnet.pl line 24.
BEGIN failed--compilation aborted at telnet.pl line 24. |
Dave | Posted at 11:08pm on Wednesday, January 30th, 2008 |
attn John Ryan.
I have the same problem, I had to do this:
$telnet->print('uname -a');
@output = $telnet->waitfor('/# $/i');
$output = "@output";
print $output;
It bugs me that it's note "right" but it works for now. |
skipo | Posted at 1:17pm on Thursday, February 14th, 2008 |
I have written a script to connect to a firewall and then telnet to a box on aht other side of that firewall (thaat's the way I have to connect). The purpose was to be able to telnet to a box without manually going thru teh intermediate steps. My code will run commands and return the results to me...until I tried to run vi. The $telnet->cmd('vi bob') just sits but never shows me the vi screen. (I assume because the comand has not completed.) is there a more interactive way to use the Net::Telnet on a character by character basis? to allow me to see the vi screen and interact with it?
Thanks, |
redhatrak | Posted at 12:16am on Wednesday, February 20th, 2008 |
I have tried this script and am getting an error when connecting to a box which actually one can ping to but cannot telnet. the telnet output of such a box is as below:
======
login: patqa1
patqa1's Password:
3004-010 Failed setting terminal ownership and mode.
======
For this error i get perl error as:
pattern match read eof at tt.pl line 24
How can this be handled? Help appreciated.
Thanks, |
pepsi | Posted at 11:43am on Wednesday, March 12th, 2008 |
Hi,
I am trying to telnet to a windows 2000 machine which has SLNet installed. I am using the following script
$telnet->open('addr1');
$telnet->login('Administrator', 'pass1');
$telnet->print('who');
@output = $telnet->waitfor('/>/');
$output = "@output";
print $output;
But the output is interspersed with junk characters. How do I ensure that these junk characters are not included in the result?
Ideally the result should be as shown below
********************************************
Administrator CONIN$ Mar 12 13:40
C:DOCUME~1ADMINI~1>
*********************************************
But when executed via script shown above, the output is displayed as shown below
*********************************************************
←[4;22H←[4;22Hwh←[4;23H←[4;24Ho←[5;1H←[5;1HAdministrator←[5;21HCONIN$←[5;34HMar
12 12:27←[7;1HC:DOCUME~1ADMINI~1 >
**********************************************************
Thanks |
topepsi | Posted at 4:04am on Wednesday, March 19th, 2008 |
i think you need to traverse the array @output per element. each element will contain per line.
might look something like this.
$output[0] = "********************************************"
$output[1] = "Administrator CONIN$ Mar 12 13:40";
... and so on
you might need a while or foreach to traverse the array |
pepsi | Posted at 8:51am on Wednesday, March 19th, 2008 |
topepsi, Thanks for your response. But it didn't work. Each array element still contains junk characters. Any other idea? |
Shankar Kundargi | Posted at 2:02am on Monday, March 24th, 2008 |
Hi,
I found the following error message while trying to connect via telnet. I am using windows XP. Is there any setting needs to be done for INC.
C:PerlsitelibURI>perl connect.pl
Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at connect.pl line 3.
BEGIN failed--compilation aborted at connect.pl line 3.
Please help me on this. |
Tayyab | Posted at 5:10am on Monday, March 24th, 2008 |
Hi Shankar,
May be you need to make a 'Net' repository in C:Perl/lib and then copy Telnet.pm there. I hope it helps. |
Shankar Kundargi | Posted at 7:09am on Monday, March 24th, 2008 |
Thanks Thayyab,
But the thing I already installed it and now I am getting Timed out error even if the login name and password are correct |
Cisco_lad | Posted at 11:25pm on Tuesday, April 8th, 2008 |
I am using below and it works fine, but only for one host.
how do I refernce host to a file of hosts. this might be trivial for u guys bit I am worse than a beginner.
Thanks in advance !
Cisco_lad
use Net::Telnet::Cisco;
my $session = Net::Telnet::Cisco->new(Host => '192.168.158.2');
$session->login('login', 'abc123');
# Enable mode
if ($session->enable("abc123") ) {
} else {
warn "Can't enable: " . $session->errmsg;
}
# Execute a command
my @output = $session->cmd('sh start | inc hostname');
print @output;
# Execute a command
@output = $session->cmd('sh ver | inc System image file is');
print @output;
$session->close; |
Thai Tuan Anh | Posted at 11:28pm on Wednesday, April 9th, 2008 |
I need to telnet to a sunser via 9023 port.
Normally, I can telnet directly as below:
telnet 10.2.4.9 9023
Trying 10.2.4.9...
Connected to 10.2.4.9.
Escape character is '^]'.
900 Login required.
login username passwd
login username passwd
102 2 records.
Lucent NavisRadius Radius Server, Version 4.5.8 (Build 551-060)
Copyright (c) 1998-2005 Lucent Technologies Inc. All Rights Reserved.
==>
I tried to use Net::Telnet with the code following:
#!/usr/bin/perl -w
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,Port => 9023,Prompt => '/==> $/');
$t->open("10.2.4.9");
$t->waitfor("900 Login required. $/i");
$t->print("login username passwd");
But it's not successful. This is the error message:
missing opening delimiter of match operator in argument "900 Login required.i" given to Net::Telnet::waitfor() at ./try line 5
How can i fix it ? |
PuneetKhurana | Posted at 5:55am on Monday, April 21st, 2008 |
Really cool stuff |
Comments to date: 55.