CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
can Net::Telnet be use for connect win to win boxes?

 



dhirajextreme
Novice

Jan 8, 2009, 2:22 AM

Post #1 of 11 (2182 views)
can Net::Telnet be use for connect win to win boxes? Can't Post

hi all,
Can any one tell me how we use Net::Telnet;
for windows machine.
i mean for windows to windows telnet connection. can i do this? If is it so then plz send me the real time code snippet
or tell me if there is another way to connect windows machine to another machine.

thanks in advance.
Dhiraj


FishMonger
Veteran / Moderator

Jan 8, 2009, 4:14 AM

Post #2 of 11 (2179 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

You need to have the telnet server service running on the box that you want to telnet into. Do you have that setup?

The doc for the Net::Telnet module has code samples that show how to connect.

Besides telnet, you can also connect via ssh, but there again you'd need to have the ssh server service running.


dhirajextreme
Novice

Jan 8, 2009, 8:19 PM

Post #3 of 11 (2174 views)
Re: [FishMonger] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

hey thanks,

I know how to use the Net::telnet but the thing is when i am connecting the windows machine( on which telnet service is started)
it is showing nothing even after successful connection.
while in case of unix machine it shows me further responses.
please help me in that scenario.

this is my code.
$Machine name is windows 2003 machine.

sub Tel_connect{

$usrname = $_[0];
$pswd= $_[1];

#for debuging
print " User name :$usrname \n Password :: $pswd \n";
$telnet_Inst = new Net::Telnet (Timeout => 300, Host => $MachineName);
$telnet_Inst->login($usrname, $pswd)
or die "Cannot establish Telnet session ", $telnet_Inst->errmsg;

#nothing is happening with the below code.
$msg = $telnet_Inst->errmsg;
my @dr=$telnet_Inst->cmd("Dir");

print " @dr \n" ;

}


FishMonger
Veteran / Moderator

Jan 9, 2009, 6:28 AM

Post #4 of 11 (2167 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

What happens when you do the telnet session from the command line? After the login do you receive a telnet prompt and can you run the dir command and receive its output?

You may need to set the prompt when creating the $telnet_Inst object and you may need to use the module's waitfor() method.

This thread may help.
http://perlguru.com/gforum.cgi?post=34743;sb=post_latest_reply;so=ASC;forum_view=forum_view_collapsed;;page=unread#unread

But a through reading of the module's doc is the best place to start.
http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm


dhirajextreme
Novice

Jan 9, 2009, 10:16 PM

Post #5 of 11 (2162 views)
Re: [FishMonger] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

thanks buddy!!!
i think it would really help..

write u soon after success or ...


dhirajextreme
Novice

Jan 12, 2009, 8:16 PM

Post #6 of 11 (2151 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

Thanks,

Its working..

but i m not able to take the output of contents of telnet likewise i do in unix

e.g. @vcheck = $telnet->print("vol");
$telnet->waitfor('/>$/');

chomp($vcheck[0]);
print " Vol is $dcheck[0]";

output::
Vol is 1


Why???

Actually output on the machine is :
+++++++++++++++++++++++++
Volume in drive C has no label.
Volume Serial Number is 4532-2345


FishMonger
Veteran / Moderator

Jan 12, 2009, 8:37 PM

Post #7 of 11 (2149 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

$telnet->print(...);
Does not return the output lines of the command you issued. The return value of 1 means that it was successful.

To retrieve the lines, you need to use either
$vol = $telnet->getline; # retrieves the first line of output
or
@vol = $telnet->getlines; # retrieves all lines of output

The documentation of the module gives a more complete example.


dhirajextreme
Novice

Jan 14, 2009, 1:39 AM

Post #8 of 11 (2139 views)
Re: [FishMonger] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

thanks once again,

now i have little bit problem with waitfor keyword.

actually i am doing installation through telnet.

but after using the following code

$telnet->print('install.exe');
$telnet->waitfor('/>$/');

it is giving me an error :

pattern match timed-out at TelnetWin.pl line 58

so tell me please how to avoid this

thanks in advance,
Dhiraj


FishMonger
Veteran / Moderator

Jan 14, 2009, 5:11 AM

Post #9 of 11 (2134 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

Either the your timeout period is too short or your regex is wrong. I'd say that the latter is more likely.

You need to adjust your regex to match the proper pattern. What that pattern needs to be I can't say because I have no idea of what you're trying to install or the prompts that it gives.


dhirajextreme
Novice

Jan 14, 2009, 11:49 PM

Post #10 of 11 (2129 views)
Re: [FishMonger] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

Thanks,

my install.exe cmd takes appox. 5 minute to complete
this is completely command base utility so no further inputs are required.

I need the timeout for the execution of this "install.exe"
for that i tried.

$t->cmd(String =>'install.exe', Timeout => 500); # NOT WORKING

$t->print(String =>'install.exe', Timeout => 500);
$t->waitfor('/>$/'); ##still not working.


$t->print('install.exe');
$t->waitfor(String =>'/>$/', Timeout => 500);
##Still not working.

Is there any other way to execute some binary or exe file on the telnet?

Thanks,
Dhiraj.


FishMonger
Veteran / Moderator

Jan 15, 2009, 4:38 AM

Post #11 of 11 (2122 views)
Re: [dhirajextreme] can Net::Telnet be use for connect win to win boxes? [In reply to] Can't Post

Have you thoroughly read the documentation for the module as I previously recommended?

Have you tried using the dump_log() or input_log() debugging methods that the module provides?


Quote
Debugging

The typical usage bug causes a time-out error because you've made incorrect assumptions about what the remote side actually sends. The easiest way to reconcile what the remote side sends with your expectations is to use input_log() or dump_log().

dump_log() allows you to see the data being sent from the remote side before any translation is done, while input_log() shows you the results after translation. The translation includes converting end of line characters, removing and responding to TELNET protocol commands in the data stream.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives