Glad to know your problem is over.
here is the perl script.
#inetd listens for rexec requests via TCP connections on port 512.
# rexec format: The input stream consists of null separated values. port for standard error\0username\0password\0command and args\0
use Socket;
$port=512;
($host, $user, $passwd, $command)=@ARGV;
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $thisaddr) = gethostbyname($host);
$thisport = pack($sockaddr, &AF_INET, 0, $thisaddr);
$thatport = pack($sockaddr, &AF_INET, $port, $thisaddr);
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "cannot create socket. Reason: $!\n";
connect(S,$thatport) || die "cannot connect socket. Reason: $!\n";
select(S); $| = 1; select(STDOUT); # Set socket to write after each print
printf S "0\0%s\0%s\0%s\0",$user,$passwd,$command; # Send command
# Read responses from server
while ( $_ = <S> ) {
printf ("$_");
}
close(S);
exit;
#end of code
besides using Socket module,you can use object-oriented IO::Socket module.(http://search.cpan.org)
the most easiest way is to grab
Net::Rexec module from cpan.org. then this two line code will do the rest. This module also supports .netrc file.(You need IO::Socket, Net::Netrc modules)
use Net::Rexec 'rexec';
($rc, @output) = rexec(host, command, userid, password);
Thanx,
[Edited by mib on 04-05-2001 at 09:39 AM]