OFFICIAL WEB SITE MAHFUD IVAN PATONI

[SCRIPT] How to pinging a host by PHP?

Tidak ada komentar



# usage; this.php domain/ip


<?php
error_reporting(0);

function ping($host){
    $starttime = microtime(true);
    $exec = fsockopen($host, 80, $errno, $errstr, 5);
    $stoptime = microtime(true);
    $status = 0;

    if (!$exec) {
        $status = "Request timed out.";
    } else {
        $status = ($stoptime - $starttime) * 1000;
        $status = "Reply from " . $host . ": bytes=32 time=" . floor($status) . "ms TTL=53";
    }
    fclose($exec);
    return $status;
}

if (preg_match('/^[a-z]{2,6}+\.[-a-z0-9]+\.[a-z]{2,6}$|^[-a-z0-9]+\.[a-z]{2,6}$/', strtolower($argv[1]))) {
    echo "\nPinging " . gethostbyaddr(gethostbyname($argv[1])) . " [" . gethostbyname($argv[1]) . "] with 32 bytes of data:\n";
    while (true) {
        echo ping(gethostbyname($argv[1])) . "\n";
        sleep(1);
    }
} elseif (preg_match('/^[0-9]{1,3}+\.[0-9]{1,3}+\.[0-9]{1,3}+\.[0-9]{1,3}$/', strtolower($argv[1]))) {
    echo "\nPinging " . $argv[1] . " with 32 bytes of data:\n";
    while (true) {
        echo ping($argv[1]) . "\n";
        sleep(1);
    }
} else {
    echo "Ping request could not find host " . $argv[1] . ". Please check the name and try again.";
}
?>

Mahfud Ivan Patoni

Tidak ada komentar :

Posting Komentar