#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use Expect;
my @serv_ip; #server's ip address
my $serv_port;
my $user;
my $pass;
my $buf;
my $msg_size;
sub usage()
{
print "Usage: $0 \n";
exit;
}
sub my_exit($)
{
print "$_[0]\n";
exit;
}
sub check_opt()
{
if(not defined($ARGV[0]))
{
usage();
}
elsif($ARGV[0] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)
{
@serv_ip = split /\./, $ARGV[0];
for(my $i = 0; $i < 4; $i++)
{
if($serv_ip[$i] < 0 || $serv_ip[$i] > 255)
{
my_exit("Illegal IP!");
}
}
}
if(not defined($ARGV[1]))
{
$serv_port = 23;
}
elsif($ARGV[1] > 0 && $ARGV[1] < 65535)
{
$serv_port = $ARGV[1];
}
else
{
my_exit("Illegal Port!");
}
}
sub get_name()
{
$user = ;
chomp($user);
}
sub get_pass()
{
print "(echo-off):";
`stty -echo`;
$pass = ;
`stty echo`;
chomp($pass);
}
sub connect_server()
{
my $timeout = 3;
my $delay = 0;
my 1104 = Expect->spawn("telnet $ARGV[0] $serv_port")
or die "Cannot spawn telnet: $!\n";
110 ->expect($timeout,-re=>'请输入帐号');
get_name();
110 ->send_slow($delay, "$user\n");
110 ->expect($timeout,-re=>'请输入密码');
get_pass();
}
check_opt();
connect_server();
阅读(1426) | 评论(0) | 转发(0) |