Ok. Well here is something that is near what I assume you are looking for.
Except, it doesn't branch on a QUERY_STRING, and of course I am not using CGI.pm.

If you so need to do that. Then you may like to branch your code via something from $ENV{QUERY_STRING}. Or even better, use CGI.pm. And have branching from something like this :
use CGI qw/:standard/; my $cgiObj = new CGI; my $addr_to_ping=$cgiObj->param('ip_address');
The url with the CGI param would look something like this : http://some-site.net/client.pl?ip_address=66.39.54.27

Client/CGI script/Ping output (to a Web browser) This works for me.
#!/usr/bin/perl #Client Script use strict; use IO::Socket; print "Content-type:text/html\n\n"; my $server="192.168.0.101"; my $server_port=23; my $nodeName = "192.168.0.101"; my $sock = new IO::Socket::INET (PeerAddr =>$server, PeerPort => $server_port , Proto => 'tcp', ) or do_exit("Couldn't connect to $server +:$server_port.\n"); print $sock "ping:$nodeName\n"; while(my $server_response=(<$sock>)) { chomp($server_response); print "Server said: $server_response<BR>" if($server_response); if($server_response eq "MOK") { exit(0); } } sub do_exit { my $err_msg=$_[0]; print "$err_msg"; exit(1); }
Server/pinger
#!/usr/bin/perl #Server Script use warnings; use strict; use IO::Socket; use IO::Select; use Net::Ping; my $serverport = 23; # create a socket to listen on SOMAXCONN = 512 my $server = new IO::Socket( Domain => PF_INET, Proto => 'tcp', LocalPort => $serverport, Listen => SOMAXCONN, ); die "Cannot bind: $!\n" unless $server; # create a 'select' object and add server fh to it my $selector = new IO::Select($server); # stop closing connections from aborting the server $SIG{PIPE} = 'IGNORE'; # loop and handle connections print "Multiplex server started on port $serverport...\n"; while (my @clients = $selector->can_read) { # input has arrived, find out which handles(s) foreach my $client (@clients) { if ($client == $server) { # it's a new connection, accept it my $newclient = $server->accept; my $port = $newclient->peerport; syswrite $newclient, "Welcome!\n"; my $name = $newclient->peerhost; $selector->add($newclient); }else{ # it's a message from an existing client my $port = $client->peerport; my $name = $client->peerhost; my ($message, $buf, $host); my $newclient = $client->accept; my $reach = Net::Ping->new($ > ? "tcp": "icmp"); (defined $reach) or die "Couldn't create Net::Ping object: $!\ +n"; if (sysread $client, $message, 1024) { print "Client $name:$port sent: $message"; while (defined ($buf = <"$message">)) { $host = (split(/:/,$buf))[1]; chomp($host); print "Remote IP to be pinged $host\n"; if($reach->ping("$host")) { print "$host is reachable\n"; print $client "reachable $host\n"; }else{ print "$host is unreachable\n"; print $client "unreachable $host\n"; } } print $client "\n Message received OK\n"; }else{ $selector->remove($client); $client->shutdown(SHUT_RDWR); print "\nClient disconnected\n"; # port, name not defined } } } }


In reply to Re: Convering Perl socket program into CGI. by kabeldag
in thread Convering Perl socket program into CGI. by rockmountain

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.