Hello! I am having trouble with a socket server and client interaction. I want to execute a perl script by default when a client TELNETs into my server. I tried this once, but it ran the script on the server's side, and not the client's side. Help?!
Here is the full code:
#! /usr/bin/perl -w
# use port 7890 as default
my $port = shift || 7890;
my $proto = getprotobyname('tcp');
# create a socket, make it reusable
socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!";
# grab a port on this machine
my $paddr = sockaddr_in($port, INADDR_ANY);
# bind to a port, then listen
bind(SERVER, $paddr) or die "bind: $!";
listen(SERVER, SOMAXCONN) or die "listen: $!";
print "SERVER started on port $port ";
# accepting a connection
while ($client_addr = accept(CLIENT, SERVER))
# find out who connected
my ($client_port, $client_ip) = sockaddr_in($client_addr);
my $client_ipnum = inet_ntoa($client_ip);
my $client_host = gethostbyaddr($client_ip, AF_INET);
# print who has connected
print "got a connection from: $client_host","[$client_ipnum] ";
# send them a message, close connection
print CLIENT "Smile from the server\n";
# open CLIENT, ("system ("perl io-test-1.pl");");
# open (CLIENT, "system ("perl io-test-1.pl")");
# open CLIENT, "do `perl io-test-1.pl`";
#my $status = CLIENT, system("perl io-test-1.pl");
#CLIENT $status = CLIENT, system("perl io-test-1.pl");
Lines 37 - 40 are my attempts at trying to run the file (in this case, called 'io-test-1.pl') to the client.
I want a default perl program to run when someone successfully TELNET's into the server.
If you want to see an example, TELNET into www.telehack.com. That is what I am trying to do, run a script when someone telnet's into the server.