SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Permissions to ping from php

  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Permissions to ping from php

    Do you have to have root access to do exec commands like ping? I'm just curious.

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    typically not, but several things (server configuration and firewall configuration in particular) could limit your ability to execute the command.

    Try it and see

    BTW, here was a remote ping script I wrote a while back:
    PHP Code:
    <html>
    <head>
    <title>NSLOOKUP and PING or TRACEROUTE from Jason's Home Computer</title>
    </head>
    <body>
    <font color=blue>
    <?php

    $shell_command 
    = ($mode == "traceroute" "traceroute -I -w 2 -q 1" "ping -c 5" );
    $command_desc "<font color=blue>" .($mode == "traceroute" "traceroute" "5 pings" ) . " to $addr from Jason's computer</font><br>\n";

    if (
    strlen($addr) > 0) {
            
    $runext exec("nslookup $addr | grep ame:"$output$error);

            if (!
    $error){
                    list(,
    $run) = each($output);
                    
    $display substr ("$run"6);
                    print 
    "Remote Address from nslookup: $display </font><p>";
            }
            if (
    $error){
              echo 
    "Unix error code: $error running nslookup $addr<BR>\n";
              exit;
            }

            
    $runext exec("$shell_command $addr"$output$error);

            if (!
    $error){
                    print 
    $command_desc;
                    while (list(,
    $line) = each($output)){
                      echo 
    $line"<BR>\n";
                    }
            }
            if (
    $error){
              echo 
    "Unix error code: $error running ping $addr<BR>\n";
              exit;
            }
    }

    print 
    "<p><center><hr size=4 width=75%><form action=$PHP_SELF method=post><b>Enter a new address to ping:<br>\n";
    print 
    "<input name=addr type=text value=\"$addr\" size=50><br>\n";
    print 
    "<input type=submit value=\"nslookup and ping\" size=30></form>\n";
    print 
    "<hr size=8 width=50%><form action=$PHP_SELF method=post><b>Or enter a new address to trace:<br>\n";
    print 
    "<input name=addr type=text value=\"$addr\" size=50><br>\n";
    print 
    "<input type=submit value=\"traceroute\"><input type=hidden name=mode value=traceroute size=30></form>\n";

    ?>
    <hr size=4 width=75%></center>
    </body>
    </html>
    Edit:

    looks like that was a "pre-register globals off" script, but hopefully you get the idea
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •