Jump to content

Contacting a address. If connection then return...


plznty

Recommended Posts

lol. yup. can you install PEAR modules? if so, install Net_ping, then create a file with this code as its content:

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Number of times to Ping the host
$count = $_GET['count'];
// Host we are pinging
$url = $_GET['ip'];
// This is the Pear Net_Ping class call
require_once "Net/Ping.php";
$ping = Net_Ping::factory();
$ping->setArgs(array('count'=>1,'timeout'=>1));
// Set variables. I know I don't have to, but why not do things right?
$transmitted = 0;
$received = 0;
$loss = 0;
$text = "";

for ($i=0; $i< $count; $i++){
        //Send ping request
        $output = $ping->ping($url);
        // If the ping returns no errors, lets parse the results.
        if (isset($output->_transmitted)){
                // Raw data, if you want to see what it returned from the ping (full text)
                $raw = $output->_raw_data;
                // This is the transmitted count. if it's zero, that means it failed in transmission. We shouldn't get a zero, but this is to handle that instance
                $trans = (string)$output->_transmitted;
                // if it successfully transmitted, lets parse the result, and add it up.
                if ($trans == 1){
                        $transmitted++;
                        $received += (string)$output->_received;
                        if ((string)$output->_loss != 0){
                                $loss++;
                                $text .=".";
                        }

                        else{
                                $text .="#";
                        }
                }
                else{
                        $transmitted++;
                        $loss++;
                        $text .=".";
                }
        }
}
echo <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<PingResults Version='1.0'>
        <PingResult Host='$url' Text='$text' Trasmitted='$transmitted' Received='$received' Loss='$loss' />
</PingResults>
EOF;
?>

now, to use it, do this: http://yourdomain.tdl/ping_file.php?ip=SomeIPOrDomain&count=TimesToPing

it will return an xml file.

 

 

is there a php only solution to this, if not how can i get perl to work

 

Warning: require_once(Net/Ping.php) [function.require-once]: failed to open stream: No such file or directory in /home/webhostg/public_html/failscape.com/ip.php on line 9

 

Fatal error: require_once() [function.require]: Failed opening required 'Net/Ping.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/webhostg/public_html/failscape.com/ip.php on line 9

are you on your own server, or remotely hosted? if you're remotely hosted, and you have ssh access, try this

pear install Net_php

if that fails, you can contact your hosting agency, and request access to PEAR.

Other than that, you can always use shell_exec to handle that, but I thin you'll see drastically slower times.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.