Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

How do I telnet into a machine and then to a third one?

by smoss (Acolyte)
on May 16, 2002 at 13:07 UTC ( #166997=categorized question: print w/replies, xml ) Need Help??
Contributed by smoss on May 16, 2002 at 13:07 UTC
Q&A  > network programming


I need to run a script using Net::Telnet which logs into one machine and then into a third machine (because of a firewall) and pull info of the third server. My script always fails after the login to the second machine.

How should I initiate the telnet session on the second machine correctly?

Answer: How do I telnet into a machine and then to a third one?
contributed by loosifer

Use or expect (the separate binary). Either should work for your purposes. Expect (the binary) is a strange language to use, so you might as well use if it will do everything you want.

As I recall, it works fine for telnet, but it can have problems with SSH. I have used it for doing nested telnets, and once you get past the initial barrier of how it works, it's pretty easy to use.

Answer: How do I telnet into a machine and then to a third one?
contributed by Marza

I don't think this is possible. You are expecting the second telnet session to be handled by Net::Telnet. It won't.

The reason is that you are running telnet as a command line tool over Net::Telnet's telnet session. Net::Telnet doesn't know that the second telnet session exists. All it knows is that you sent some keystrokes to the remote server. The remote server is the one initiating and managing the telnet session.

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2020-10-01 05:24 GMT
    Find Nodes?
      Voting Booth?
      If at first I donít succeed, I Ö

      Results (174 votes). Check out past polls.