نمایش آنلاین ping?

ninjaghaleb

Member
با سلام:rose:

من سورس php نیاز دارم که بتونه پینگ سروری رو آنلان نشون بده:cool:

مثلا اگه سرور روشنه یک عکس سبز رنگ رو نشون بده و مقداره پینک رو جلولوش بذاره:paint:
و گه خاموشه فقط یک عکس سیاه نشون بده:neutral:

اگه میتونید کمک کنید:oops:

با تشکر:rose:
 

ziXet

مدیر انجمن PHP/MYSQL
با سلام:rose:

من سورس php نیاز دارم که بتونه پینگ سروری رو آنلان نشون بده:cool:

مثلا اگه سرور روشنه یک عکس سبز رنگ رو نشون بده و مقداره پینک رو جلولوش بذاره:paint:
و گه خاموشه فقط یک عکس سیاه نشون بده:neutral:

اگه میتونید کمک کنید:oops:

با تشکر:rose:
PHP:
<?php
// 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);
}
// Making the package
$type= "\x08";
$code= "\x00";
$checksum= "\x00\x00";
$identifier = "\x00\x00";
$seqNumber = "\x00\x00";
$data= "Scarface";
$package = $type.$code.$checksum.$identifier.$seqNumber.$data;
$checksum = icmpChecksum($package); // Calculate the checksum
$package = $type.$code.$checksum.$identifier.$seqNumber.$data;
// And off to the sockets
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_connect($socket, "www.google.com", null);
// If you're using below PHP 5, see the manual for the microtime_float
// function. Instead of just using the microtime() function.
$startTime = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255)) {
echo round(microtime(true) - $startTime, 4) .' seconds';
}
socket_close($socket);
?>
 

ninjaghaleb

Member
با سلام


آقا من IP رو کجا قرار بدم

و این دو متغییر Scarface و Secuond رو باید چه کار کرد؟
 

ziXet

مدیر انجمن PHP/MYSQL
با سلام


آقا من IP رو کجا قرار بدم

و این دو متغییر Scarface و Secuond رو باید چه کار کرد؟
کد رو به صورت تابع در آوردم:
PHP:
<?php
// 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);
}
function ping($ip){
    // Making the package
    $type= "\x08";
    $code= "\x00";
    $checksum= "\x00\x00";
    $identifier = "\x00\x00";
    $seqNumber = "\x00\x00";
    $data= "Scarface";
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    $checksum = icmpChecksum($package); // Calculate the checksum
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    // And off to the sockets
    $socket = socket_create(AF_INET, SOCK_RAW, 1);
    socket_connect($socket, $ip, null);
    // If you're using below PHP 5, see the manual for the microtime_float
    // function. Instead of just using the microtime() function.
    $startTime = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
    return round(microtime(true) - $startTime, 4) .' seconds';
    }
    socket_close($socket);
}

echo "ping Google : ".ping("www.google.com")."<br/>";
echo "ping Yahoo : ".ping("www.yahoo.com");
//echo "ping 123.43.21.22 : ".ping("123.43.21.22");

?>
فقط کافیه تابع ping رو فراخونی کنید
 

ninjaghaleb

Member
این http://nodroon.com/ping.php v رو نگاه کنین

کدش هم اینه

PHP:
<?php
// 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);
}
function ping($ip){
    // Making the package
    $type= "\x08";
    $code= "\x00";
    $checksum= "\x00\x00";
    $identifier = "\x00\x00";
    $seqNumber = "\x00\x00";
    $data= "Scarface";
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    $checksum = icmpChecksum($package); // Calculate the checksum
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    // And off to the sockets
    $socket = socket_create(AF_INET, SOCK_RAW, 1);
    socket_connect($socket, $ip, null);
    // If you're using below PHP 5, see the manual for the microtime_float
    // function. Instead of just using the microtime() function.
    $startTime = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
    return round(microtime(true) - $startTime, 4) .' seconds';
    }
    socket_close($socket);
}

echo "S2 : ".ping("209.59.231.59")."<br/>";
echo "S1 : ".ping("209.59.231.23");
//echo "ping 123.43.21.22 : ".ping("123.43.21.22");

?>
 

ziXet

مدیر انجمن PHP/MYSQL
این http://nodroon.com/ping.php v رو نگاه کنین

کدش هم اینه

PHP:
<?php
// 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);
}
function ping($ip){
    // Making the package
    $type= "\x08";
    $code= "\x00";
    $checksum= "\x00\x00";
    $identifier = "\x00\x00";
    $seqNumber = "\x00\x00";
    $data= "Scarface";
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    $checksum = icmpChecksum($package); // Calculate the checksum
    $package = $type.$code.$checksum.$identifier.$seqNumber.$data;
    // And off to the sockets
    $socket = socket_create(AF_INET, SOCK_RAW, 1);
    socket_connect($socket, $ip, null);
    // If you're using below PHP 5, see the manual for the microtime_float
    // function. Instead of just using the microtime() function.
    $startTime = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
    return round(microtime(true) - $startTime, 4) .' seconds';
    }
    socket_close($socket);
}

echo "S2 : ".ping("209.59.231.59")."<br/>";
echo "S1 : ".ping("209.59.231.23");
//echo "ping 123.43.21.22 : ".ping("123.43.21.22");

?>
مدیر هاستینگ شما اجازه استفاده از توابع socket رو به شما نداده
شما باید با ایشون تماس بگیرید

موفق باشید
 

جدیدترین ارسال ها

بالا