Alright Monks?

I am trying to write a script that will listen on a specified port, accepting connections only from listed IP's, and accept/run commands.

For example, i could telnet/use another script to connect to the server running this script on port 12345, pass a command such as 'touch blah' followed by another command such as 'touch mooo', and those commands would be run on the remote machine.

The code i have so far is here:
#!/usr/bin/perl use Socket; $SOMAXCONN=2; socket(SERVER, AF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "ca +nt create socket $!"; setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1) || warn "cant make socket + reusable\n"; bind(SERVER, sockaddr_in(8850, INADDR_ANY)) || die "cant bind IP to so +cket $!";; listen(SERVER, SOMAXCONN) || die "cant listen on port $!";; print "server PID $$ is listening\n"; while(){ $REMOT_ADDR=accept(CLIENT, SERVER); # after connection ($R_port,$R_addr)=sockaddr_in($REMOT_ADDR); $R_addr=inet_ntoa($R_addr); print "connection from $R_addr on $R_port\n"; }
Can anybody help me on this one?

In reply to Sockets, And Running Commands. by hiddenlinux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.