示例#1
0
function GetLatency($host, $port)
{
    /**
        -> composer.json
        ======================================
        {
            "minimum-stability": "dev",
            "require": {
                "geerlingguy/ping": "1.*@dev"
            }
        }
        ======================================
        **/
    #$host = "www.google.com.tr";
    #$port = 443;
    $handle = new Ping($host);
    if (isset($port)) {
        $handle->setPort($port);
    }
    $latency = $handle->ping("fsockopen");
    $status = array("<div class='online'> {$latency} ms </div>", "<div class='offline'>Error</div>");
    if ($latency !== false) {
        return $status[0];
    } else {
        return $status[1];
    }
}
 /**
  * ping host
  *
  * @param   string  $host         url bni ecollection
  * @return  boolean true
  * @throws  BillingException  when url cannot ping
  */
 public static function host($host)
 {
     if (filter_var($host, FILTER_VALIDATE_URL) === false) {
         throw new BillingException("Invalid Host");
     }
     $ping = new Ping(rtrim(preg_replace('#^https?://#', '', $host), '/'));
     $latency = $ping->ping();
     if ($latency == false) {
         throw new BillingException("Cannot reach host");
     }
     return true;
 }
示例#3
0
 /**
  * These tests require sudo/root so socket can be opened.
  */
 public function testPingSocket()
 {
     $ping = new Ping($this->reachable_host);
     $latency = $ping->ping('socket');
     $this->assertNotEquals(FALSE, $latency);
     $ping = new Ping($this->unreachable_host);
     $latency = $ping->ping('socket');
     $this->assertEquals(FALSE, $latency);
 }
示例#4
0
<?php

date_default_timezone_set("Asia/Jakarta");
include "Ping.php";
use JJG\Ping;
$hosts[] = "192.168.200.3";
$hosts[] = "192.168.200.4";
$hosts[] = "192.168.200.2";
$host = false;
foreach ($hosts as $item) {
    $ping = new Ping($item);
    $latency = $ping->ping();
    if ($latency !== false) {
        $host = $item;
        break;
    }
}
$route = `route -n`;
$cekRoute = strpos($route, $host);
$pos = strpos($route, "8.8.8.8");
if ($cekRoute === false && $pos !== false) {
    delRoute();
}
$route = `route -n`;
$pos = strpos($route, "8.8.8.8");
if ($host !== false) {
    if ($pos === false) {
        addRoute($host);
        echo date("d-M-Y H:i:s") . " route added {$host}\n";
    } else {
        echo date("d-M-Y H:i:s") . " nothing to do\n";
示例#5
0
 /**
  * @param int $ttl
  * @return $this
  */
 public function setTtl($ttl)
 {
     parent::setTtl($ttl);
     return $this;
 }
示例#6
0
 /**
  * Checks the ping of the host
  * 
  * @return double|false
  */
 public function ping()
 {
     $this->ping = $this->pinger->ping();
     return $this->getPing();
 }
示例#7
0
文件: ping.php 项目: spigotx/HomeLab2
/**
	-> composer.json
	======================================
	{
		"minimum-stability": "dev",
		"require": {
			"geerlingguy/ping": "1.*@dev"
		}
	}
	======================================
	**/
/**
 * vendor/autoload.php dosyası Composer tarafından
 * oluşturulmaktadır.
 */
require "vendor/autoload.php";
use JJG\Ping;
# Host adresi ( IP adreside girilebilir. )
$host = "www.google.com.tr";
# Port numarası ( girmesenizde olur. )
$port = 443;
$handle = new Ping($host);
if (isset($port)) {
    $handle->setPort($port);
}
$latency = $handle->ping("fsockopen");
if ($latency !== false) {
    echo "Latency is {$latency} ms";
} else {
    echo "Host could not be reached.";
}