Re: printing output of ping command -- New question at bottom.

From: John W. Krahn (krahnj_at_telus.net)
Date: 02/23/05


Date: Wed, 23 Feb 2005 12:50:22 -0800
To: Perl Beginners <beginners@perl.org>

Tyson Sommer wrote:
>
> This might be a question for beginners-cgi, but since it was mentioned
> here...
>
> I tried to use Net::Ping in a CGI script and it said I didn't have
> permissions to run ping. I can execute the section of the CGI script with
> the call to Net::Ping just fine from the cmd line as a regular user. If I
> use backticks instead, the script runs just fine via the CGI. Any
> suggestions? I'm still somewhat novice on a *nix box, so I don't know what
> to change to allow ping to be run from Net::Ping via the CGI interface (via
> Apache).
>
> Assume warnings, strictures, and that a new CGI has been called (everything
> else in the script works fine), blah, blah:
>
> my $pinger = Net::Ping->new("icmp") || die;
> my $device = $q->param('device');
>
> if( $pinger->ping($host,2) ){
> print "$host is online\n";
> }
> else{
> print "$host is offline\n";
> }
>
> This gets me an error in my browser saying I don't have permission to run
> ping (yes, using CGI::Carp... As well for troubleshooting).

perldoc Net::Ping
[snip]
        If the "icmp" protocol is specified, the ping() method sends an icmp
        echo message to the remote host, which is what the UNIX ping program
        does. If the echoed message is received from the remote host and the
        echoed information is correct, the remote host is considered reachable.
        Specifying the "icmp" protocol requires that the program be run as root
        or that the program be setuid to root.

Your web server does not run as root so you have to use either TCP or UDP
instead of ICMP.

John

-- 
use Perl;
program
fulfillment


Relevant Pages

  • Re: Testing Perl on a Web Page
    ... Jeff Westman wrote: ... That is a pretty big leap, involving file permissions, etc. ... this situation is to make a sister directory to the one in which I have my CGI ... script, and make it group writable. ...
    (perl.beginners)
  • Re: cgi-bin Permisions
    ... permissions to allow the script to run. ... I personally have not seen a CGI ... you are, which you should be, using an HTTP connection you would be ...
    (microsoft.public.inetserver.iis.security)
  • Re: dynamic lib ignored even after "found" in "install_driver(Oracle) failed: Cant load..." cgi prob
    ... the solution i found is this: i moved the directory containing libclntsh.so under /usr/lib, which is a location that apache seems to trust, as opposed to where i had originally placed this directory. ... so, if i knew then what i know now, here are the steps _I_ would use were i to install the oracle instantclient such that the DBD::Oracle module would work when used in an apache 2.0 CGI: ... i also could run it this way by placing tnsnames.ora in my home directory as .tnsnames.ora, but this location will do me no good when i want apache to run the script as a cgi. ... am i missing some sort of configuration detail regarding apache and permissions granted a cgi? ...
    (perl.dbi.users)
  • Re: CGI Problem
    ... your perl is) is the first line with NO LINES above it, ... Using the Unix Permissions function of your FTP program, ... Attempt to run the script from your browser. ... you have successfuly installed and executed a cgi script. ...
    (AIX-L)
  • Re: Key-passing from PHP to TCL CGI script - how is it done (web security issue)?
    ... TCL v.8.3 ... set hasEnteredTrivia 0 ... # NEW 8/7/2004 USE PHP (AS CGI) TO CHECK IF USER IS ATTEMPTING TO ENTER ... # USE REMOTE PHP SCRIPT TO CHECK FOR REPOSTING ...
    (comp.lang.tcl)