Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/01/2006, 13:08
Shockly
 
Fecha de Ingreso: agosto-2005
Mensajes: 109
Antigüedad: 18 años, 8 meses
Puntos: 0
Yo uso esto... a partir de ahí, puedes procesar el resultado como desees.

Un saludo.

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="es-MX">
<head>
<title>Ping to Planet with 32 data bytes</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<STYLE type=text/css>
BODY { FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: Verdana,arial, helvetica, serif; margin : 25 25 25 25;}
</STYLE>
</head>
<BODY bgcolor="#D5D5D5" text="#000000" id="all" leftmargin="25" topmargin="25" marginwidth="25" marginheight="25" link="#000020" vlink="#000020" alink="#000020">
<?php
/*

//        http://localhost/ping.php

*/
//---------------------------------------------------------------------------------------------------
//  definiciones

    
error_reportingE_ALL );

//---------------------------------------------------------------------------------------------------
//  funciones

    // Checksum calculation function
    
function icmpChecksum($data) {
        if (
strlen($data)%2)
            
$data .= "\x00";
        
$bit unpack('n*'$data);
        
$sum array_sum($bit);
        while (
$sum >> 16)
            
$sum = ($sum >> 16) + ($sum 0xffff);
        return 
pack('n*', ~$sum);
    }

//---------------------------------------------------------------------------------------------------
//  main

    
echo "<center><b>Ping to 'XxXxXx' with 32 data bytes</b><br>";
    echo 
"</center><br>";
    echo 
"<br><pre><br>";

    
    
// Making the package
    
$type"\x08";                                                                                                        //  Echo Request
    
$code"\x00";
    
$checksum"\x00\x00";
    
$identifier "\x00\x00";
    
$seqNumber "\x00\x00";
    
$datamd5(microtime(true));                                                                                    //  32 bytes de datos
    
$package $type.$code.$checksum.$identifier.$seqNumber.$data;
    
$checksum icmpChecksum($package);                                                             // Calculate the checksum
    
$package $type.$code.$checksum.$identifier.$seqNumber.$data;
    
    
$timeout 15;  //timeout in seconds
   
    // And off to the sockets
    
$socket socket_createAF_INETSOCK_RAW)
        or die(
"Unable to create socket\n");

    
socket_clear_error();
    
$time time();
    while ( !@
socket_connect($socket"www.XxXxXx.com"null )) {
        if ((
time() - $time) >= $timeout) {
            
socket_close($socket);
            die(
"Connection timed out.\n");
        }
        
$err socket_last_error($socket);
        if (
$err == 115 || $err == 114) {
            if ((
time() - $time) >= $timeout) {
                
socket_close($socket);
                die(
"Connection timed out.\n");
            }
            
sleep(1);
            continue;
        }
        die(
socket_strerror($err) . "\n");
    }
        
    
$startTime microtime(true);
    
socket_send($socket$packagestrLen($package), 0);
    if (
socket_read($socket255)) {
        
$stopTime microtime(true);
        
$pingTime $stopTime $startTime;
        if( 
$pingTime ) {
            
$stopTime    += 1.0;        
            
$pingTime $stopTime $startTime;
        }
        
$pingTime bcsub$pingTime0);
        echo 
"$pingTime seconds<br>";
    }
    
socket_close($socket);


    echo 
"<br>";
    echo 
"</pre><hr><br>";
    echo 
"<center><small>";
    echo 
date("l dS of F Y - h:i:s A") . "<br>";
    echo 
"</small></center>";
    echo 
"</body>";
    echo 
"</html>";

//---------------------------------------------------------------------------------------------------
//    END
?>