Help Required using NET::TELNET Module ??

Discussion in 'Perl Misc' started by mark1.thompson45@btinternet.com, Dec 29, 2005.

  1. Guest

    Hello,
    I need to know how you telnet from one host to another using
    the net::telnet module. I can telnet to a single host OK but I need to
    telnet from that host to a 2nd machine, I cannot get this to work, I
    merely start anothet telnet session (spawn a new telnet session) from
    my host machine.

    i.e.

    this works:-
    host machine -------> machine A

    this does not:-
    host machine -------> machine A -----------> machine B


    I am using:-

    $script = new Net::Telnet (Timeout=>5, Errmode=>'return',
    Prompt=>'/[\$?>:#\]] *$/');

    I need to do this as some devices (machine B) I
    am trying to contact can only be accessed from a jumpstart server
    (machine A).


    cheers, Mark.
    , Dec 29, 2005
    #1
    1. Advertising

  2. Gratemyl Guest

    wrote:
    > Hello,
    > I need to know how you telnet from one host to another using
    > the net::telnet module. I can telnet to a single host OK but I need to
    > telnet from that host to a 2nd machine, I cannot get this to work, I
    > merely start anothet telnet session (spawn a new telnet session) from
    > my host machine.
    >
    > i.e.
    >
    > this works:-
    > host machine -------> machine A
    >
    > this does not:-
    > host machine -------> machine A -----------> machine B
    >
    >
    > I am using:-
    >
    > $script = new Net::Telnet (Timeout=>5, Errmode=>'return',
    > Prompt=>'/[\$?>:#\]] *$/');
    >
    > I need to do this as some devices (machine B) I
    > am trying to contact can only be accessed from a jumpstart server
    > (machine A).
    >
    >
    > cheers, Mark.


    Please include some more (if not all) code, then better support can be
    given. My understanding is that you would like to make a connection to
    machine B, which originates from machine A. Though this is possible,
    you will need to give more info, so we can help.

    Yours,

    Gratemyl
    Gratemyl, Dec 29, 2005
    #2
    1. Advertising

  3. Guest

    you ae correct, I would like the connection to machine B to originate
    from machine A and not from the machine where the script is executed
    from. I have attached the code if it will help, it basically loops
    through a list of machines executing the 'telnet' command:-

    open (HOSTS, "D:\\Documents and Settings\\801825642\\My
    Documents\\tom1.txt");
    while (my $line = <HOSTS>)
    {
    if ($line =~ m/--/)
    {
    #print "Comment Line Only\n";
    } else {
    @Data = split(":", $line);
    $uid = $Data[2];
    $pwd = $Data[3];
    chomp $Data[6];
    ## check if a jumpastart server is required
    if ($Data[4] ne '')
    {
    $jump_host = $Data[4];
    $uid = $Data[5];
    $pwd = $Data[6];
    jump_start();
    } else {
    $jump_host = $Data[1];
    Telnet_To_Device();
    }

    }
    }

    close(HOSTS);
    create_csv();
    create_webpage();
    exit 0;


    sub Telnet_To_Device
    {
    if ($jump == 0)
    {
    #print "\n\nTELNET CONNECTION EXISTS\n\n";
    $script = new Net::Telnet ( Timeout=>5, Errmode=>'return', Prompt =>
    '/[\$?>:#\]] *$/');
    } else {
    $script = new Net::Telnet ( Timeout=>5, Errmode=>'return', Prompt
    => '/[\$?>:#\]] *$/');
    }
    #$script->dump_log(@Data[0]."debug.log");
    #$script->input_log('STDERR');

    if (!($script->open($jump_host))) {
    print "FAILED TO CONNECT TO $Data[0]\n";
    return;
    } else {
    #print "\n\n>>$uid<-->$pwd<<\n\n";
    print "\n\n$Data[0]:$Data[4]\n";
    if ($jump)
    {
    #print "DO NOT ADD TO HASH - AS ONLY JUMPSTART\n";
    } else {
    $Output{$Data[0]} = "$Data[1],$Data[0],";
    }
    sleep 1;
    $script->waitfor('/login:/i');
    $script->print($uid);
    sleep 1;
    $script->waitfor('/password:/i');
    my ($Before,$After) = $script->print($pwd);
    sleep 1;
    #print "B=$Before <==> A=$After\n";

    #----------> check password is correct <-----------#

    my ($Before,$After) = $script->waitfor('/Do you/');
    #print "B=$Before <--> A=$After\n";
    #sleep 5;

    if ($After =~ m/do you understand/i)
    {
    print "IN SECURITY...\n";
    $script->print('Y');
    if ($Data[2] =~ m/nsg/i)
    {
    print "IN NSG...\n";
    sleep 0.5;
    $script->waitfor('/Please hit/i');
    #print "B=$Before <==> A=$After\n";
    $script->print('\n'); # nsg accounts - carriage return
    sleep 0.5;
    $script->waitfor('/[\$?>:#\]] *$/');
    #print "B=$Before <==> A=$After\n";
    } else {
    print "NOT NSG ACCOUNT...\n";
    sleep 0.5;
    my ($Before,$After) = $script->waitfor('/[\$#] $/');
    #print "B=$Before <==> A=$After\n";
    }

    } else { # straight to box prompt
    #sleep 2;
    print "NO WARNING...\n";
    my ($Before,$After) = $script->waitfor('/[\$?>:#\]] *$/');
    #my ($Before,$After) = $script->waitfor('/[\$%#>)/');
    #print "B=$Before <==> A=$After\n";
    }

    if ($jump)
    {
    #print "Going from TELNET to JUMP\n";
    return;
    } else {
    omnihome();
    uname();
    box_type();
    procmon();
    logmon();
    netbackup();
    webtop();
    impact();
    rad();
    #--------------------------------------#
    trap_dest();
    osmf_tools();
    disk_space();
    omnibus();
    disk_size();




    $script->print('exit');
    }
    }
    }
    , Dec 29, 2005
    #3
  4. Guest

    this is the jumpstart subroutine that I left off the previous post:-

    sub jump_start
    {
    #print "\n\nIN JUMP START\n";
    $jump = 1;
    Telnet_To_Device();
    $jump_host = $Data[1];
    $uid = $Data[2];
    $pwd = $Data[3];
    $jump = 0;
    Telnet_To_Device();
    }
    , Dec 29, 2005
    #4
  5. robic0 Guest

    On 29 Dec 2005 03:19:39 -0800, wrote:

    >Hello,
    > I need to know how you telnet from one host to another using
    >the net::telnet module. I can telnet to a single host OK but I need to
    >telnet from that host to a 2nd machine, I cannot get this to work, I
    >merely start anothet telnet session (spawn a new telnet session) from
    >my host machine.
    >
    >i.e.
    >
    >this works:-
    >host machine -------> machine A
    >
    >this does not:-
    >host machine -------> machine A -----------> machine B
    >
    >
    >I am using:-
    >
    >$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
    >Prompt=>'/[\$?>:#\]] *$/');
    >
    >I need to do this as some devices (machine B) I
    >am trying to contact can only be accessed from a jumpstart server
    >(machine A).
    >
    >
    >cheers, Mark.


    Thats a good question. The only reason I can see to try
    something like this is if seperate networks.

    The connectiion is actually:

    host machine (you, client) --------------> machine A (server)

    machine A (your telnet session)----------> machine A (start a telnet client)

    machine A (your remote client)-----------> machine B (server)

    between remote machine A (start a telnet client)---------> machine B (server)
    you have to have machine B's i/o console redirected to you the host machine.

    This isin't something you want to try with the perl net::telnet module until
    you know it works manually. The big problem with telnet is the Unix/Windows
    conflicting clients as it relates to the Telnet standard protocol.
    So trying this between OS's is just asking for trouble.

    I have automated a telnet session from a client windows to a unix machine with
    net::telnet. There are limitations. I have made workarounds for them.
    I wrote a module (class) for this that wraps net::telnet. If you can get it working
    by hand, let me know and I'll post the module here and you can give it a try.

    -robic0-
    robic0, Jan 1, 2006
    #5
  6. robic0 Guest

    On Sat, 31 Dec 2005 16:18:39 -0800, robic0 wrote:

    >On 29 Dec 2005 03:19:39 -0800, wrote:
    >
    >>Hello,
    >> I need to know how you telnet from one host to another using
    >>the net::telnet module. I can telnet to a single host OK but I need to
    >>telnet from that host to a 2nd machine, I cannot get this to work, I
    >>merely start anothet telnet session (spawn a new telnet session) from
    >>my host machine.
    >>
    >>i.e.
    >>
    >>this works:-
    >>host machine -------> machine A
    >>
    >>this does not:-
    >>host machine -------> machine A -----------> machine B
    >>
    >>
    >>I am using:-
    >>
    >>$script = new Net::Telnet (Timeout=>5, Errmode=>'return',
    >>Prompt=>'/[\$?>:#\]] *$/');
    >>
    >>I need to do this as some devices (machine B) I
    >>am trying to contact can only be accessed from a jumpstart server
    >>(machine A).
    >>
    >>
    >>cheers, Mark.

    >
    >Thats a good question. The only reason I can see to try
    >something like this is if seperate networks.
    >
    >The connectiion is actually:
    >
    >host machine (you, client) --------------> machine A (server)
    >
    >machine A (your telnet session)----------> machine A (start a telnet client)
    >
    >machine A (your remote client)-----------> machine B (server)
    >
    >between remote machine A (start a telnet client)---------> machine B (server)
    >you have to have machine B's i/o console redirected to you the host machine.
    >
    >This isin't something you want to try with the perl net::telnet module until
    >you know it works manually. The big problem with telnet is the Unix/Windows
    >conflicting clients as it relates to the Telnet standard protocol.
    >So trying this between OS's is just asking for trouble.
    >
    >I have automated a telnet session from a client windows to a unix machine with
    >net::telnet. There are limitations. I have made workarounds for them.
    >I wrote a module (class) for this that wraps net::telnet. If you can get it working
    >by hand, let me know and I'll post the module here and you can give it a try.
    >
    >-robic0-
    >


    Just one other thing. If you intend to automate with net::telnet from A to B
    you will need net::telnet on machine A (as a client) as well.
    robic0, Jan 1, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Isaacson
    Replies:
    5
    Views:
    593
    Default User
    Nov 5, 2004
  2. Carcarius
    Replies:
    0
    Views:
    275
    Carcarius
    Dec 6, 2007
  3. Robert
    Replies:
    0
    Views:
    107
    Robert
    Sep 11, 2003
  4. Prashant Varghese

    Net-Telnet-Cisco module

    Prashant Varghese, Sep 26, 2003, in forum: Perl Misc
    Replies:
    9
    Views:
    189
    Prashant Varghese
    Sep 30, 2003
  5. Asterix
    Replies:
    5
    Views:
    174
Loading...

Share This Page