Loading ...
Sorry, an error occurred while loading the content.

Telnet Client or CRT Help?

Expand Messages
  • EleqTrizi'T
    Greetings! I m a relative newcomer to Perl, but have done a bit of programming in it already. I was wondering how I would go about programming a Telnet Client
    Message 1 of 3 , Nov 7, 2000
    • 0 Attachment
      Greetings!

      I'm a relative newcomer to Perl, but have done a bit of programming
      in it already. I was wondering how I would go about programming a
      Telnet Client in Perl that could interface with say....a BBS?

      Also, has anyone ever run a Perl script in Vandyke's
      (www.vandyke.com) CRT or SecureCRT program before?

      Regards,

      A. Rivera
    • Gerrit P. Haase
      Message 2 of 3 , Nov 12, 2000
      • 0 Attachment
        <7 Nov 2000, 18:57 Uhr wars, als EleqTrizi'T folgendes schrub:>
        < [PBML] Telnet Client or CRT Help? >

        Hi Eleq,

        > I'm a relative newcomer to Perl, but have done a bit of programming
        > in it already. I was wondering how I would go about programming a
        > Telnet Client in Perl that could interface with say....a BBS?

        Try to use the module Net::Telnet, Copyright by Jay Rogers.

        perldoc Net::Telnet
        man Net::Telnet

        otherwise: http://search.cpan.org

        ciao,

        - gph -

        --
        Gerrit Peter Haase
        ¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤
      • Gerrit P. Haase
        Message 3 of 3 , Nov 12, 2000
        • 0 Attachment
          <7 Nov 2000, 18:57 Uhr wars, als EleqTrizi'T folgendes schrub:>
          < [PBML] Telnet Client or CRT Help? >

          SEE ALSO
          RFC 854
          TELNET Protocol Specification

          ftp://ftp.isi.edu/in-notes/rfc854.txt

          RFC 1143
          Q Method of Implementing TELNET Option Negotiation

          ftp://ftp.isi.edu/in-notes/rfc1143.txt

          TELNET Option Assignments
          ftp://ftp.isi.edu/in-notes/iana/assignments/telnet-options

          EXAMPLES
          This example gets the current weather forecast for Brainerd, Minnesota.

          my ($forecast, $t);

          use Net::Telnet ();
          $t = new Net::Telnet;
          $t->open("rainmaker.wunderground.com");

          ## 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("BRD");

          ## Read and print the first page of forecast.
          ($forecast) = $t->waitfor('/[ \t]+press return to continue/i');
          print $forecast;

          exit;

          This example checks a POP server to see if you have mail.

          my ($hostname, $line, $passwd, $pop, $username);

          $hostname = "your_destination_host_here";
          $username = "your_username_here";
          $passwd = "your_password_here";

          use Net::Telnet ();
          $pop = new Net::Telnet (Telnetmode => 0);
          $pop->open(Host => $hostname,
          Port => 110);

          ## Read connection message.
          $line = $pop->getline;
          die $line unless $line =~ /^\+OK/;

          ## Send user name.
          $pop->print("user $username");
          $line = $pop->getline;
          die $line unless $line =~ /^\+OK/;

          ## Send password.
          $pop->print("pass $passwd");
          $line = $pop->getline;
          die $line unless $line =~ /^\+OK/;

          ## Request status of messages.
          $pop->print("list");
          $line = $pop->getline;
          print $line;

          exit;

          Here's an example you can use to down load a file of any type. The file
          is read from the remote host's standard output using cat. To prevent any
          output processing, the remote host's standard output is put in raw mode
          using the Bourne shell. The Bourne shell is used because some shells,
          notably tcsh, prevent changing tty modes. Upon completion, FTP style
          statistics are printed to stderr.

          my ($block, $filename, $host, $hostname, $k_per_sec, $line,
          $num_read, $passwd, $prevblock, $prompt, $size, $size_bsd,
          $size_sysv, $start_time, $total_time, $username);

          $hostname = "your_destination_host_here";
          $username = "your_username_here";
          $passwd = "your_password_here";
          $filename = "your_download_file_here";

          ## Connect and login.
          use Net::Telnet ();
          $host = new Net::Telnet (Timeout => 30,
          Prompt => '/[%#>] $/');
          $host->open($hostname);
          $host->login($username, $passwd);

          ## Make sure prompt won't match anything in send data.
          $prompt = '_funkyPrompt_';
          $host->prompt("/$prompt\$/");
          $host->cmd("set prompt = '$prompt'");

          ## Get size of file.
          ($line) = $host->cmd("/bin/ls -l $filename");
          ($size_bsd, $size_sysv) = (split ' ', $line)[3,4];
          if ($size_sysv =~ /^\d+$/) {
          $size = $size_sysv;
          }
          elsif ($size_bsd =~ /^\d+$/) {
          $size = $size_bsd;
          }
          else {
          die "$filename: no such file on $hostname";
          }

          ## Start sending the file.
          binmode STDOUT;
          $host->binmode(1);
          $host->print("/bin/sh -c 'stty raw; cat $filename'");
          $host->getline; # discard echoed back line

          ## Read file a block at a time.
          $num_read = 0;
          $prevblock = '';
          $start_time = time;
          while (($block = $host->get) and ($block !~ /$prompt$/o)) {
          if (length $block >= length $prompt) {
          print $prevblock;
          $num_read += length $prevblock;
          $prevblock = $block;
          }
          else {
          $prevblock .= $block;
          }

          }
          $host->close;

          ## Print last block without trailing prompt.
          $prevblock .= $block;
          $prevblock =~ s/$prompt$//;
          print $prevblock;
          $num_read += length $prevblock;
          die "error: expected size $size, received size $num_read\n"
          unless $num_read == $size;

          ## Print totals.
          $total_time = (time - $start_time) || 1;
          $k_per_sec = ($size / 1024) / $total_time;
          $k_per_sec = sprintf "%3.1f", $k_per_sec;
          warn("$num_read bytes received in $total_time seconds ",
          "($k_per_sec Kbytes/s)\n");

          exit;

          AUTHOR
          Jay Rogers <jay@...>

          COPYRIGHT
          Copyright 1997, 2000 by Jay Rogers. All rights reserved. This program is
          free software; you can redistribute it and/or modify it under the same
          terms as Perl itself.

          - gph -

          --
          Gerrit Peter Haase
          ¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤
        Your message has been successfully submitted and would be delivered to recipients shortly.