At 2:49 PM -0800 1/15/03, shirish doshi wrote:
Shirish,Hi, I am a novice in Perl and I want to implement telnet in perl. If you have any tutorials or source code available with you , please forward me. Thanking you in advance, Regards, Shirish
Perl has the Net::Telnet module:
http://search.cpan.org/author/JROGERS/Net-Telnet-3.03/
Below, I'll include an example I created following the module's example in its manpage. This example doesn't require a username and password. Most of the information you need will be in the manpage. Once you install the module, use 'perldoc Net::Telnet' to read it.
Paul
#!/usr/bin/perl
# get_weather.pl
#
# This script connects to the Weather Underground site and
# retrieves a brief weather report for the designated city.
# [Based on example in Net::Telnet POD. Added config section and
# line ending substitution statement before output. -- PJC]
use strict;
use Net::Telnet;
# # # Begin Config # # #
my $url = "rainmaker.wunderground.com";
my $city_code = "PHL"; # Philadelphia, PA, USA
# # # End Config # # #
my($forecast, $t);
use Net::Telnet ();
$t = new Net::Telnet;
$t->open($url);
## Wait for first prompt and "hit return".
$t->waitfor('/continue:.*$/');
$t->print("");
## Wait for second prompt and respond with city code.
$t->waitfor('/city code.*$/');
$t->print($city_code);
## Read and print the first page of forecast.
($forecast) = $t->waitfor('/[ \t]+press return to continue/i');
# replace orig. line ending with Mac EOL char.
$forecast =~ s/\015?\012/\015/g; # DOS/UNIX to Mac [PJC]
print $forecast;
exit;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]