2001-02-18 14:18:13 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use Socket;
|
|
|
|
use Getopt::Std;
|
|
|
|
|
|
|
|
$Usage = qq{
|
|
|
|
Usage: $0 options command...
|
|
|
|
|
|
|
|
Options: -d hostname destination hostname (default: localhost)
|
2010-04-02 12:25:50 +02:00
|
|
|
-p port SVDRP port number (default: 6419)
|
2001-02-18 14:18:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
die $Usage if (!$ARGV[0] || !getopts("d:p:"));
|
|
|
|
|
|
|
|
$Dest = $opt_d || "localhost";
|
2010-04-02 12:25:50 +02:00
|
|
|
$Port = $opt_p || 6419;
|
2001-02-18 14:18:13 +01:00
|
|
|
$Cmd = "@ARGV" || Error("missing command");
|
|
|
|
|
|
|
|
$Timeout = 10; # max. seconds to wait for response
|
|
|
|
|
|
|
|
$SIG{ALRM} = sub { Error("timeout"); };
|
|
|
|
alarm($Timeout);
|
|
|
|
|
|
|
|
$iaddr = inet_aton($Dest) || Error("no host: $Dest");
|
|
|
|
$paddr = sockaddr_in($Port, $iaddr);
|
|
|
|
|
|
|
|
$proto = getprotobyname('tcp');
|
|
|
|
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || Error("socket: $!");
|
|
|
|
connect(SOCK, $paddr) || Error("connect: $!");
|
|
|
|
select(SOCK); $| = 1;
|
|
|
|
Receive();
|
|
|
|
Send($Cmd);
|
|
|
|
Send("quit");
|
|
|
|
close(SOCK) || Error("close: $!");
|
|
|
|
|
|
|
|
sub Send
|
|
|
|
{
|
|
|
|
my $cmd = shift || Error("no command to send");
|
|
|
|
print SOCK "$cmd\r\n";
|
|
|
|
Receive();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub Receive
|
|
|
|
{
|
|
|
|
while (<SOCK>) {
|
|
|
|
print STDOUT $_;
|
|
|
|
last if substr($_, 3, 1) ne "-";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub Error
|
|
|
|
{
|
|
|
|
print STDERR "@_\n";
|
|
|
|
close(SOCK);
|
2011-08-06 09:51:09 +02:00
|
|
|
exit 1;
|
2001-02-18 14:18:13 +01:00
|
|
|
}
|
|
|
|
|