看到的dump log总是显示undetermine terminal type。
## Module import.
use Net::Telnet qw(TELNET_IAC TELNET_SB TELNET_SE TELOPT_TTYPE);
## Global variables.
my $Term;
## Main program.
{
my $host = "your_destination_host_here";
my $user = "your_username_here";
my $passwd = "your_password_here";
my $prompt = '/bash\$ $/';
# your regexp for shell prompt here
my $t;
$t = new Net::Telnet (Prompt => $prompt);
## Set up callbacks to negotiate terminal type.
$t->option_callback(sub {});
$t->suboption_callback(\&subopt_callback);
$t->option_accept(Do => TELOPT_TTYPE);
## Login and print value of TERM.
$Term = "dumb";
$t->open($host);
$t->login($user, $passwd);
print $t->cmd('hostname');
print "TERM=", $t->cmd('echo $TERM');
$t->close;
exit;
}
# end main program
sub subopt_callback {
my ($t, $option, $parameters) = @_;
my $telcmd;
if ($option == TELOPT_TTYPE) {
$telcmd = pack("C4 A* C2", TELNET_IAC, TELNET_SB, TELOPT_TTYPE, 0, $Term, TELNET_IAC, TELNET_SE);
$t->put(String => $telcmd, Telnetmode => 0);
}
1;
} # end sub subopt_callback
用其中的这个部分的代码,就可以自动判断终端类型,实现想要的东西