use Net::Telnet;
use IO::Socket;
use Getopt::Long;
my $Host;
my $User;
my $Pwss;
my $Command;
my $Output;
my $string;
my $obj;
my $ref;
my $cmd;
&processargs;
$Host='hemo370';
$User='administrateur';
$Pwss='master77ab';
$Command='1494';
### FUNC: getargs
sub processargs {
GetOptions (
"H|host=s" => \$Host,
"C|command=s" => \$Command,
"U|user=s" => \$User,
"P|password=s" => \$Pwss,
);
}
#print "Host: ".$Host." User: ".$User.$Pwss." CMD: ".$Command."\n";
#exit;
if ($Host eq "" || $Command eq "" || $User eq "" || $Pwss eq ""){
print "\nCommand usage: ./check_telnet -H host IP -U user -P password -C command\n";
exit;
}
else{
&connect
sub connect{
my $conn = new Net::Telnet ( Timeout => "5");
$conn->binmode(1); # don't translate CRLF
$conn->errmode("return"); # enable error trapping
$conn->telnetmode(0); # turn off telnet mode
$conn->dump_log("LOGFILE"); # output log file filehandle
$conn->output_record_separator("");
unless ($conn->open(Host => 'hemo370', Port => '1494'))
{
die "Error opening socket:: ".$conn->errmsg();
}
print "Connected to ".$conn->host().", port ".$conn->port()."\n";
@num = $conn->cmd(String => "\r",
Prompt => '/ICA/');
print @num;
# send 's' to the ADC and wait until '>' is returned
@num = $conn->cmd(String => "s",
Prompt => '/ICA/');
print @num;
# close telnet connection
$conn->close;
}
Partager