Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

telnet through perl

Status
Not open for further replies.

vmiharia

Programmer
Joined
Mar 18, 2004
Messages
1
Location
US
Hi Perl Gurus,
___________________________________________________________
Here is what I want to DO:
I am trying to telnet to a server and after authenticating myself, I am trying to write the output to a page
-----------------------------------------------------------
___________________________________________________________
Part of my code:

my $host = shift || $hostName;
my $port = shift || 23;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp');
if($sock) # if successfully connected
{

# send message to server
print $sock "xxxxxxx\n"; #sending the userName
print $sock "xxxxx\n"; # sending the password
print $sock "command\n"; # command that i want to execute

open(IN,$fileToWrite); # open the file to write

#Want to loop until the end of data received
while (<$sock>)
{
$line = $_;
print IN $line; # write it to file
}
close(IN);
close $sock or die "close: $!";
}
-----------------------------------------------------------
Problem I am FACING:
When I try to run it, It does not finish printing out to the text file. It stops after Password: Here is the output
-------------------------------------------------
Use of this system by unauthorized persons or in an

unauthorized manner is strictly prohibited.

username: XXXXXX


Password:
-------------------------------------------------
It just ends here.The rest of the data never gets printed

Can some one tell me what to do?

Thanks a lot for your time
 
Try something like ...

$port = new Net::Telnet (Timeout => 10, Errmode => "Return", Prompt => $prompt);
$port->open( $computer);
$port->login( $username, $passwd);
 
hi ,
i use this ...

#!/usr/local/bin/perl
#######################################################################################
## Autore : Michele Bulloni - michele.bulloni@postecom.it
#######################################################################################
use Net::Telnet;
use strict;


#my $cli_user = 'cn=manager';
#my $cli_pw = 'password';
my $node = '<machine>';
my $port = '<port>';

my $prompt = '/\[N\/S\]\> /';
my $comando;
$comando=$ARGV[0];
my $t = new Net::Telnet ( Timeout => 5,
Prompt => "$prompt",
Errmode => 'return',
Dump_log => 'dump.log',
Input_log => 'in.log',
Output_Log => 'out.log',

);

print "\nConnecting: $node $port\n";

unless ( $t->open (Host => $node, Port => $port) ){
print "ERROR: not able to connect, node:$node port:$port\n";
exit 1;
}

$t->cmd('login password write');

$t->cmd($comando);
print "$comando\n";
print "Operazione Terminata!!\n";

#my @data = $t->cmd('find Routing_Label');
#print @data;

# @data remains empty!

$t->cmd('quit');


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top