Dear monks, i am writing a script to telnet to device by telnet session from a cisco router...ie ...telnet in a telnet..here im posting my code..the first telnet is working fine but from that session i need to telnet into a local device which is a private ip...when im using this code im getting an error that port:23 not connected...can anybody help me how to write telnet in telnet code...thanks in advance

use Net::Cisco; use Net::Telnet(); $t =Net::Telnet::Cisco->new(Host=>'$ip'); print "connected"; $t->login('', ''); $t->cmd("telnet 192.168.201.3"); $k=Net::Telnet->new(Timeout=>10,Errmode=>'die'); $k->open("192.168.201.3")or die "$k->errmsg"; print "connected"; $k->waitfor('password:$/i'); $k->print("public"); $k->waitfor('>$/i'); @output=$k->print("show system"); open(CONFIG,">config.txt"); print CONFIG "@output\n"; close(CONFIG); $k->close; $t->close;
Guys ....i am updating the above code ..finallly i got it...thanks to perlbotics here's the updated code....
use Net::Cisco; my $t =Net::Telnet::Cisco->new(Host=>'10.0.0.1'); my @output; my $tl=0; $t->login('9190','KUM@R425'); $t->print('telnet 192.168.203.23')or $tl=1; $t->waitfor('/Please enter password: /'); $t->print('public'); $t->waitfor('/]> /'); @output=$t->cmd(string=>"show system",prompt=>'/]>/'); print @output; print "$output[4]\n"; print "$output[11]\n"; $t->print('exit'); open(CONFIG,">config.csv"); print CONFIG "$output[4]^$output[11]\n"; close(CONFIG); $t->close;

In reply to telnet from a cisco telnet by Kumar Mantri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.